﻿<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>STJson</title>
<link rel="shortcut icon" href="./favicon.png" type="image/png"/>
<link rel="stylesheet" type="text/css" href="./css/stdoc.css"/>
<script type="text/javascript" src="./js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="./js/stdoc.js"></script>
</head>
<body>
<div id="div_model" style="display:none">SINGLE</div>
<div id="div_body">
<div id="div_logo"></div>
<div id="div_left">
<div id="div_left_list">
<ul class='ul_group_root'>
<li>
    <a class='a_node_root anchor_btn' name='a_a' href='#a_a'>STLib.STJson</a>
    <ul>
        <li class='li_node_sub'><a class='anchor_btn' name='a_b' href='#a_b'>Introduction</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='a_c' href='#a_c'>Path question</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='a_d' href='#a_d'>Expression question</a></li>
    </ul>
</li>
<li>
    <a class='a_node_root anchor_btn' name='a_e' href='#a_e'>STJson API</a>
    <ul>
        <li class='li_node_sub'><a class='anchor_btn' name='a_f' href='#a_f'>Data mapping</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='a_g' href='#a_g'>Static functions</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='a_h' href='#a_h'>Non-Static functions</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='a_i' href='#a_i'>Extended functions</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='a_j' href='#a_j'>Fields</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='a_k' href='#a_k'>Indexer</a></li>
    </ul>
</li>
<li>
    <a class='a_node_root anchor_btn' name='a_l' href='#a_l'>STJson [Basic]</a>
    <ul>
        <li class='li_node_sub'><a class='anchor_btn' name='a_m' href='#a_m'>object -&gt; string</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='a_n' href='#a_n'>string -&gt; object</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='a_o' href='#a_o'>STJsonConverter</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='a_p' href='#a_p'>STJsonAttribute</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='a_q' href='#a_q'>STJsonSetting</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='a_r' href='#a_r'>json_src</a></li>
    </ul>
</li>
<li>
    <a class='a_node_root anchor_btn' name='a_s' href='#a_s'>STJsonPath</a>
    <ul>
        <li class='li_node_sub'><a class='anchor_btn' name='a_t' href='#a_t'>Selector</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='a_u' href='#a_u'>How to use</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='a_v' href='#a_v'>Wildcard character</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='a_w' href='#a_w'>Depth selector</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='a_x' href='#a_x'>List selector</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='a_y' href='#a_y'>Slice selector</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='a_z' href='#a_z'>Expression</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='b_a' href='#b_a'>Filter expression</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='b_b' href='#b_b'>General expression</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='b_c' href='#b_c'>Test expression</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='b_d' href='#b_d'>Build-In functions</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='b_e' href='#b_e'>Build-In functions list</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='b_f' href='#b_f'>Custom functions</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='b_g' href='#b_g'>Selectors in expressions</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='b_h' href='#b_h'>Select mode</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='b_i' href='#b_i'>ParsedTokens</a></li>
    </ul>
</li>
<li>
    <a class='a_node_root anchor_btn' name='b_j' href='#b_j'>STJson [Advanced]</a>
    <ul>
        <li class='li_node_sub'><a class='anchor_btn' name='b_k' href='#b_k'>Get value</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='b_l' href='#b_l'>Set value</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='b_m' href='#b_m'>Callback</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='b_n' href='#b_n'>PathItem</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='b_o' href='#b_o'>Clone</a></li>
    </ul>
</li>
<li>
    <a class='a_node_root anchor_btn' name='b_p' href='#b_p'>Aggregation</a>
    <ul>
        <li class='li_node_sub'><a class='anchor_btn' name='b_q' href='#b_q'>sort</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='b_r' href='#b_r'>group</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='b_s' href='#b_s'>terms</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='b_t' href='#b_t'>min, max</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='b_u' href='#b_u'>avg, sum</a></li>
        <li class='li_node_sub'><a class='anchor_btn' name='b_v' href='#b_v'>STJsonPath.Name</a></li>
    </ul>
</li>
<li>
    <a class='a_node_root anchor_btn' name='b_w' href='#b_w'>The END</a>
    <ul>
        
    </ul>
</li>
</ul><div class='div_left_space_space'></div>
</div>
<span id="span_time">2023-06-07 -> by:<span>DebugST</span></span>
</div>
<div id="div_right">
<h1 class='h_title anchor_point' name='a_a'>STLib.STJson</h1>
<div><h2 class='h_option anchor_point' name='a_b'>Introduction</h2></div>
<p><span class='mark'>STLib.STJson</span>is a<span class='mark'>Json</span>parsing library based on the<span class='mark'>MIT</span>open source protocol. powered by <a class='mark' target='_blank' href='https://github.com/DebugST'>DebugST</a>.The pure native implementation of the library does not rely on any library, so it is very lightweight, convenient, and powerful. Since it does not rely on pure native construction, it can be easily transplanted to other programming languages. Of course, because the author is lazy, the probability is not very high.</p>
<p>When designing <span class='mark'>STJson</span>, the author did not have any objection. After all, there was no dispute about the data format of <span class='mark'>Json</span>. When designing <span class='mark'>STJsonPath</span>, the author hesitated, because the author found many controversial places and could not find a formal <span class='mark'>RFC</span> document about <span class='mark'>JsonPath</span>, but only found a draft:</p>
<p><a class='mark' target='_blank' href='https://www.ietf.org/archive/id/draft-ietf-jsonpath-base-03.html'>JSONPath: Query expressions for JSON</a></p>
<p>Although some doubts in the draft can also be solved, the author still has some doubts. After all, it is not an official document. Before development, the author was also curious about other open source libraries of <span class='mark'>JsonPath</span>, and how other libraries resolve controversial issues. Unfortunately, the problem still exists. No developer seems willing to refer to this draft. Since there is no formal RFC document for <span class='mark'>JsonPath</span>, the author also wants to establish his own portal. However, the author will not ignore this draft. The author will try to be compatible with the draft as much as possible, and will also add some of his own ideas.</p>
<div><h2 class='h_option anchor_point' name='a_c'>Path question</h2></div>
<p><span class='mark'>JsonPath</span> is derived from the use of <span class='mark'>XPath</span>, which is known to be the XML Path Language, a language used to determine the location of a part of an <span class='mark'>XML</span> document. Obviously <span class='mark'>JsonPath</span> is used for <span class='mark'>Json</span>. They are both used in almost the same way, but the differences between the two data formats <span class='mark'>XML</span> and <span class='mark'>Json</span> are bound to have their differences.</p>
<p>For example, there are no special characters in the element name of <span class='mark'>XML</span>, but the <span class='mark'>Key</span> of <span class='mark'>Json</span> can be any string, if there is <span class='mark'>Json</span> data:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span>{ <span style='color:rgba(255,165,0,1)'>"aa"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span> <span style='color:rgba(255,165,0,1)'>"bb"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"cc"</span> <span style='color:rgba(255,255,255,1)'>} }</span></pre>
</div>
<p>In <span class='mark'>JsonPath</span> we can get the value <span class='mark'>cc</span> by the path <span class='mark'>aa.bb</span> without any problem, what if the <span class='mark'>Json</span> data is replaced by the following:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span>{ <span style='color:rgba(255,165,0,1)'>"a.a"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span> <span style='color:rgba(255,165,0,1)'>"bb"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"cc"</span> <span style='color:rgba(255,255,255,1)'>} }</span></pre>
</div>
<p>Obviously the value <span class='mark'>cc</span> is not available through <span class='mark'>a.a.bb</span>. Maybe normally <span class='mark'>Json</span> represents an object, and objects don't have such strange properties. But for the data format of <span class='mark'>Json</span>, its <span class='mark'>Key</span> can be any character. Even if you pass <span class='mark'>{OBJ_NAME}.a.a.bb</span> in the browser, you will only get an error. But the way the browser accesses the <span class='mark'>Json</span> element is not just through <span class='mark'>. </span>, there is also the indexer <span class='mark'>{OBJ_NAME}['a.a']['bb']</span> that can get the correct value.</p>
<p>The use of <span class='mark'>'</span> or <span class='mark'>"</span> is allowed in <span class='mark'>STJsonPath</span>, which is marked as <span class='mark'>String</span> in the lexical parser (STJsonPathTokenizer.cs), and if this string is in the scope of a non-expression, the parser (STJsonPathParser.cs) will re-tag it as <span class='mark'>Property </span> as an index to avoid special strings that can't be handled, and strings support <span class='mark'>\</span> for escaping. So you can use <span class='mark'>'a.a'.bb</span> in <span class='mark'>STJsonPath</span> to get the correct value. And a similar treatment is indeed mentioned in the draft.</p>
<div><h2 class='h_option anchor_point' name='a_d'>Expression question</h2></div>
<p>In the draft there is mention of supporting expressions and that there are two types of expressions, <span class='mark'>()</span> and <span class='mark'>? ()</span>. They stand for <span class='mark'>ordinary expressions</span> and <span class='mark'>filtered expressions</span> respectively. And according to the author's understanding, <span class='mark'>ordinary expression</span> is used to calculate a value and use this value as part of <span class='mark'>JsonPath</span>, such as <span class='mark'>$.books[(@.length - 1)]</span> which can be seen in many cases. It is possible to perform recursion on <span class='mark'>Json</span> elements when executing <span class='mark'>JsonPath</span>, where <span class='mark'>@</span> is a dynamic variable that indicates the <span class='mark'>Json</span> element currently being processed during the recursion, and according to the surface meaning of the expression is trying to get the last element in <span class='mark'>books</span>.</p>
<p>But how does <span class='mark'>@.length</span> get executed? Where does <span class='mark'>length</span> come from? If <span class='mark'>@</span> is an array, the author can tentatively understand that it is finding the length of the array? But what if <span class='mark'>@</span> is an object?</p>
<p>Since it is an expression, what kind of syntax can be written in <span class='mark'>()</span>? What about the syntax? About all these queries the author has used his own implementation, which will be introduced in a later tutorial.</p>
<h1 class='h_title anchor_point' name='a_e'>STJson API</h1>
<div><h2 class='h_option anchor_point' name='a_f'>Data mapping</h2></div>
<div class='div_table'>
<table>
<tr><th>.Net</th><th>STJsonValueType</th><th>.Net</th><th>STJsonValueType</th></tr>
<tr><td>byte</td><td>Long</td><td>sbyte</td><td>Long</td></tr>
<tr class='tr_hight'><td>short</td><td>Long</td><td>ushort</td><td>Long</td></tr>
<tr><td>int</td><td>Long</td><td>uint</td><td>Long</td></tr>
<tr class='tr_hight'><td>long</td><td>Long</td><td>ulong</td><td>Long</td></tr>
<tr><td>float</td><td>Double</td><td>double</td><td>Double</td></tr>
<tr class='tr_hight'><td>decimal</td><td>Double</td><td>bool</td><td>Boolean</td></tr>
<tr><td>char</td><td>String</td><td>string</td><td>String</td></tr>
<tr class='tr_hight'><td>DateTime</td><td>String</td><td>enum</td><td>Long or String</td></tr>
<tr><td>Point</td><td>Array</td><td>PointF</td><td>Array</td></tr>
<tr class='tr_hight'><td>Size</td><td>Array</td><td>SizeF</td><td>Array</td></tr>
<tr><td>Rectangle</td><td>Array</td><td>RectangleF</td><td>Array</td></tr>
<tr class='tr_hight'><td>Color</td><td>Array</td><td>DataTable</td><td>Object</td></tr>
<tr><td>Array</td><td>Array</td><td>ICollection</td><td>Array</td></tr>
<tr class='tr_hight'><td>IDectionary</td><td>Object</td><td>object</td><td>Object</td></tr>
</table>
</div>
<p><span class='mark'>STJson</span> covers the common basic data types, even if they are not included, then the properties of the object will be recurred by performing reflection in the end.</p>
<div><h2 class='h_option anchor_point' name='a_g'>Static functions</h2></div>
<div class='div_hightlight' style='background-color:goldenrod;color:black'>
<p><span class='mark'>(+n)</span> in the following indicates that there are multiple overloads.</p>
</div>
<div class='div_table'>
<table>
<tr><th>return</th><th>signature</th><th>note</th></tr>
<tr><td>string</td><td>Serialize(+n)</td><td>Serialize an <span class='mark'>object</span> object to a string.</td></tr>
<tr class='tr_hight'><td>STJson</td><td>Deserialize(string)</td><td>Convert a string to <span class='mark'>STJson</span> object order.</td></tr>
<tr><td>T</td><td>Deserialize&lt;T&gt;(+n)</td><td>Converts an object or string to a target object.</td></tr>
<tr class='tr_hight'><td>STJson</td><td>STJson CreateObject()</td><td>Create an empty object。</td></tr>
<tr><td>STJson</td><td>STJson CreateArray(params object[])</td><td>Create an array object。</td></tr>
<tr class='tr_hight'><td>STJson</td><td>FromObject(+n)</td><td>Converts an object to <span class='mark'>STJson</span>.</td></tr>
<tr><td>string</td><td>Format(+n)</td><td>Format a <span class='mark'>Json</span> string.</td></tr>
<tr class='tr_hight'><td>void</td><td>AddCustomConverter(+n)</td><td>Add custom type converter.</td></tr>
<tr><td>void</td><td>RemoveCustomConverter(+n)</td><td>Remove custom type converter</td></tr>
</table>
</div>
<div><h2 class='h_option anchor_point' name='a_h'>Non-Static functions</h2></div>
<div class='div_table'>
<table>
<tr><th>return</th><th>signature</th><th>note</th></tr>
<tr><td>STJson</td><td>SetItem(+n)</td><td>Adds a key-value pair to the object and returns itself.</td></tr>
<tr class='tr_hight'><td>STJson</td><td>SetKey(string)</td><td>Adds a <span class='mark'>key</span> to the object and returns the target object.</td></tr>
<tr><td>void</td><td>SetValue(+n)</td><td>Set the value of the target object.</td></tr>
<tr class='tr_hight'><td>STJson</td><td>Delete(string)</td><td>Removes a <span class='mark'>key</span> from the object and returns the target object.</td></tr>
<tr><td>STJson</td><td>Append(+n)</td><td>Adds one or some elements to the array object and returns itself.</td></tr>
<tr class='tr_hight'><td>STJson</td><td>Insert(+n)</td><td>Inserts an element into the array object and returns itself.</td></tr>
<tr><td>STJson</td><td>RemoveAt(int nIndex)</td><td>Removes an index from the array object.</td></tr>
<tr class='tr_hight'><td>void</td><td>Clear()</td><td>Clear all child elements.</td></tr>
<tr><td>IEnumerator&lt;STJson&gt;</td><td>GetEnumerator()</td><td>Get all the child elements of the current element.</td></tr>
<tr class='tr_hight'><td>STJson</td><td>Clone</td><td>Clone the current element.</td></tr>
</table>
</div>
<div><h2 class='h_option anchor_point' name='a_i'>Extended functions</h2></div>
<div class='div_table'>
<table>
<tr><th>return</th><th>signature</th><th>note</th></tr>
<tr><td>STJson</td><td>Set(+n)</td><td>Set the object according to the path (STJsonPath).</td></tr>
<tr class='tr_hight'><td>string</td><td>GetValue(+n)</td><td>Get the string value of the object (value-type only)</td></tr>
<tr><td>T</td><td>GetValue&lt;T&gt;(+n)</td><td>Get the value of the object (value-type only)</td></tr>
<tr class='tr_hight'><td>STJson</td><td>Select(+n)</td><td>Filter data in an object.</td></tr>
<tr><td>STJson</td><td>SelectFirst(+n)</td><td>Filter data in the object and select the first result.</td></tr>
<tr class='tr_hight'><td>STJson</td><td>SelectLast(+n)</td><td>Filters through the data in the object and selects the last result.</td></tr>
<tr><td>STJson</td><td>Group(+n)</td><td>Groups the specified fields.</td></tr>
<tr class='tr_hight'><td>STJson</td><td>Terms(+n)</td><td>Count the number of values for the specified field.</td></tr>
<tr><td>STJson</td><td>Sort(+n)</td><td>Sort the specified fields.</td></tr>
<tr class='tr_hight'><td>STJson</td><td>Min(+n)</td><td>Tally the minimum value of the specified field.</td></tr>
<tr><td>STJson</td><td>Max(+n)</td><td>Tally the maximum value of the specified field.</td></tr>
<tr class='tr_hight'><td>STJson</td><td>Sum(+n)</td><td>Tally the total number of the specified fields.</td></tr>
<tr><td>STJson</td><td>Avg(+n)</td><td>Tally the average of the specified fields.</td></tr>
</table>
</div>
<div><h2 class='h_option anchor_point' name='a_j'>Fields</h2></div>
<div class='div_table'>
<table>
<tr><th>type</th><th>name</th><th>note</th></tr>
<tr><td>string</td><td>Key</td><td>the <span class='mark'>Key</span> of the parent element of the current `STJson</td></tr>
<tr class='tr_hight'><td>object</td><td>Value</td><td>the value of the current <span class='mark'>STJson</span>, or <span class='mark'>null</span> if the current <span class='mark'>STJson</span> is not of value type</td></tr>
<tr><td>bool</td><td>IsNullObject</td><td>whether the current <span class='mark'>STJson</span> is a null element, i.e. the data type of the current <span class='mark'>STJson</span> value cannot be determined.</td></tr>
<tr class='tr_hight'><td>int</td><td>Count</td><td>The number of child elements contained in the current <span class='mark'>STJson</span>.</td></tr>
<tr><td>STJsonValueType</td><td>ValueType</td><td>(enumeration) The data type of the current element.</td></tr>
</table>
</div>
<p><span class='mark'>STJsonValueType</span> is the following value:</p>
<p><span class='mark'>Undefined</span> <span class='mark'>String</span> <span class='mark'>Boolean</span> <span class='mark'>Long</span> <span class='mark'>Double</span> <span class='mark'>Datetime</span> <span class='mark'>Array</span> <span class='mark'>Object</span></p>
<div><h2 class='h_option anchor_point' name='a_k'>Indexer</h2></div>
<ul>
<li>STJson STJson[int]</li>
<li>STJson STJson[string]</li>
</ul>
<h1 class='h_title anchor_point' name='a_l'>STJson [Basic]</h1>
<p><span class='mark'>STJson</span> is an intermediate data type that is a bridge between <span class='mark'>string</span> and <span class='mark'>object</span> and is very convenient to use, e.g:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> st_json <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(255,255,255,1)'>()</span>
<span class='span_code_line'></span>    <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"number"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>)</span>               <span style='color:rgba(0,255,0,1)'>// The function returns itself, so it can be operated continuously</span>
<span class='span_code_line'></span>    <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"boolean"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>)</span>
<span class='span_code_line'></span>    <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"string"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"this is string"</span><span style='color:rgba(255,255,255,1)'>)</span>
<span class='span_code_line'></span>    <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"datetime"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(0,255,255,1)'>DateTime</span><span style='color:rgba(112,128,144,1)'>.Now</span><span style='color:rgba(255,255,255,1)'>)</span>
<span class='span_code_line'></span>    <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"array_1"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.CreateArray</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>123</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"string"</span><span style='color:rgba(255,255,255,1)'>))</span>
<span class='span_code_line'></span>    <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"array_2"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.FromObject</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(100,149,237,1)'>object</span><span style='color:rgba(255,255,255,1)'>[] {</span> <span style='color:rgba(144,238,144,1)'>123</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"string"</span> <span style='color:rgba(255,255,255,1)'>}))</span>
<span class='span_code_line'></span>    <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"object"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(255,255,255,1)'>{</span> key <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(255,165,0,1)'>"this is a object"</span> <span style='color:rgba(255,255,255,1)'>})</span>
<span class='span_code_line'></span>    <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"null"</span><span style='color:rgba(255,255,255,1)'>,</span> obj<span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>st_json<span style='color:rgba(219,112,147,1)'>.SetKey</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"key"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.SetValue</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"this is a test"</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>st_json<span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span> <span style='color:rgba(0,255,0,1)'>// 4 -> indentation space count
<span class='span_code_line'></span>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"number"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"boolean"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"string"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"this is string"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"datetime"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"2023-04-22T21:12:30.6109410+08:00"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"array_1"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>        <span style='color:rgba(144,238,144,1)'>123</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"string"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>],</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"array_2"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>        <span style='color:rgba(144,238,144,1)'>123</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"string"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>],</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"object"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"key"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"this is a object"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>},</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"null"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"key"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"this is a test"</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>}</span></pre>
</div>
<div class='div_hightlight' style='background-color:pink;color:black'>
<p>When executing <span class='mark'>var st_json = new STJson()</span>, <span class='mark'>st_json</span> is the empty element, i.e. <span class='mark'>st_json.IsNullObject = true</span>. Because at this point it is not possible to determine whether <span class='mark'>st_json</span> is an <span class='mark'>object</span> or an <span class='mark'>array</span> or a <span class='mark'>value</span>.</p>
<p>There are no objects like <span class='mark'>JArray</span> or <span class='mark'>JObject</span> in <span class='mark'>STJson</span>, <span class='mark'>STJson</span> can be either <span class='mark'>Array</span> or <span class='mark'>Object</span>. <span class='mark'>STJson</span> has two indexers <span class='mark'>[int]</span><span class='mark'>[string]</span>.</p>
</div>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> json_1 <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(255,255,255,1)'>();</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"[json_1] - "</span> <span style='color:rgba(255,255,255,1)'>+</span> json_1<span style='color:rgba(112,128,144,1)'>.IsNullObject</span> <span style='color:rgba(255,255,255,1)'>+</span> <span style='color:rgba(255,165,0,1)'>" - "</span> <span style='color:rgba(255,255,255,1)'>+</span> json_1<span style='color:rgba(112,128,144,1)'>.ValueType</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>
<span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> json_2 <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(255,255,255,1)'>();</span>
<span class='span_code_line'></span>json_2<span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"key"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"[json_2] - "</span> <span style='color:rgba(255,255,255,1)'>+</span> json_2<span style='color:rgba(112,128,144,1)'>.IsNullObject</span> <span style='color:rgba(255,255,255,1)'>+</span> <span style='color:rgba(255,165,0,1)'>" - "</span> <span style='color:rgba(255,255,255,1)'>+</span> json_2<span style='color:rgba(112,128,144,1)'>.ValueType</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>
<span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> json_3 <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(255,255,255,1)'>();</span>
<span class='span_code_line'></span>json_3<span style='color:rgba(219,112,147,1)'>.Append</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>2</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>3</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"[json_3] - "</span> <span style='color:rgba(255,255,255,1)'>+</span> json_3<span style='color:rgba(112,128,144,1)'>.IsNullObject</span> <span style='color:rgba(255,255,255,1)'>+</span> <span style='color:rgba(255,165,0,1)'>" - "</span> <span style='color:rgba(255,255,255,1)'>+</span> json_3<span style='color:rgba(112,128,144,1)'>.ValueType</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>
<span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> json_4 <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(255,255,255,1)'>();</span>
<span class='span_code_line'></span>json_4<span style='color:rgba(219,112,147,1)'>.SetValue</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>DateTime</span><span style='color:rgba(112,128,144,1)'>.Now</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"[json_4] - "</span> <span style='color:rgba(255,255,255,1)'>+</span> json_4<span style='color:rgba(112,128,144,1)'>.IsNullObject</span> <span style='color:rgba(255,255,255,1)'>+</span> <span style='color:rgba(255,165,0,1)'>" - "</span> <span style='color:rgba(255,255,255,1)'>+</span> json_4<span style='color:rgba(112,128,144,1)'>.ValueType</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>
<span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> json_5 <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.CreateArray</span><span style='color:rgba(255,255,255,1)'>();</span>          <span style='color:rgba(0,255,0,1)'>// made by static function</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"[json_5] - "</span> <span style='color:rgba(255,255,255,1)'>+</span> json_5<span style='color:rgba(112,128,144,1)'>.IsNullObject</span> <span style='color:rgba(255,255,255,1)'>+</span> <span style='color:rgba(255,165,0,1)'>" - "</span> <span style='color:rgba(255,255,255,1)'>+</span> json_5<span style='color:rgba(112,128,144,1)'>.ValueType</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>
<span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> json_6 <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.CreateObject</span><span style='color:rgba(255,255,255,1)'>();</span>         <span style='color:rgba(0,255,0,1)'>// made by static function</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"[json_6] - "</span> <span style='color:rgba(255,255,255,1)'>+</span> json_6<span style='color:rgba(112,128,144,1)'>.IsNullObject</span> <span style='color:rgba(255,255,255,1)'>+</span> <span style='color:rgba(255,165,0,1)'>" - "</span> <span style='color:rgba(255,255,255,1)'>+</span> json_6<span style='color:rgba(112,128,144,1)'>.ValueType</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>
<span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> json_7 <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.FromObject</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>12</span><span style='color:rgba(255,255,255,1)'>);</span>         <span style='color:rgba(0,255,0,1)'>// made by static function</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"[json_3] - "</span> <span style='color:rgba(255,255,255,1)'>+</span> json_7<span style='color:rgba(112,128,144,1)'>.IsNullObject</span> <span style='color:rgba(255,255,255,1)'>+</span> <span style='color:rgba(255,165,0,1)'>" - "</span> <span style='color:rgba(255,255,255,1)'>+</span> json_7<span style='color:rgba(112,128,144,1)'>.ValueType</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span>json_1<span style='color:rgba(255,255,255,1)'>]</span> <span style='color:rgba(255,255,255,1)'>-</span> True <span style='color:rgba(255,255,255,1)'>-</span> None
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span>json_2<span style='color:rgba(255,255,255,1)'>]</span> <span style='color:rgba(255,255,255,1)'>-</span> False <span style='color:rgba(255,255,255,1)'>-</span> Object
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span>json_3<span style='color:rgba(255,255,255,1)'>]</span> <span style='color:rgba(255,255,255,1)'>-</span> False <span style='color:rgba(255,255,255,1)'>-</span> Array
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span>json_4<span style='color:rgba(255,255,255,1)'>]</span> <span style='color:rgba(255,255,255,1)'>-</span> False <span style='color:rgba(255,255,255,1)'>-</span> Datetime
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span>json_5<span style='color:rgba(255,255,255,1)'>]</span> <span style='color:rgba(255,255,255,1)'>-</span> False <span style='color:rgba(255,255,255,1)'>-</span> Array
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span>json_6<span style='color:rgba(255,255,255,1)'>]</span> <span style='color:rgba(255,255,255,1)'>-</span> False <span style='color:rgba(255,255,255,1)'>-</span> Object
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span>json_7<span style='color:rgba(255,255,255,1)'>]</span> <span style='color:rgba(255,255,255,1)'>-</span> False <span style='color:rgba(255,255,255,1)'>-</span> Long</span></pre>
</div>
<div class='div_hightlight' style='background-color:goldenrod;color:black'>
<p>When <span class='mark'>ValuteType = Array</span>, <span class='mark'>SetItem(+n)</span> cannot be called, and when <span class='mark'>ValueType = Object</span>, <span class='mark'>Append(+n)</span> cannot be called. But <span class='mark'>ValueType</span> can be forced to change by <span class='mark'>SetValue(+n)</span>.</p>
</div>
<p>As mentioned above <span class='mark'>STJson</span> has two indexers through which you can access them, or get the values.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> json_temp <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.CreateArray</span><span style='color:rgba(255,255,255,1)'>()</span>
<span class='span_code_line'></span>    <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"string"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"this is string"</span><span style='color:rgba(255,255,255,1)'>)</span>
<span class='span_code_line'></span>    <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"array"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>Object</span><span style='color:rgba(255,255,255,1)'>[] {</span> <span style='color:rgba(255,165,0,1)'>"1"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"2"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"3"</span> <span style='color:rgba(255,255,255,1)'>});</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_temp<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(255,165,0,1)'>"string"</span><span style='color:rgba(255,255,255,1)'>]);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_temp<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(255,165,0,1)'>"string"</span><span style='color:rgba(255,255,255,1)'>]</span><span style='color:rgba(219,112,147,1)'>.GetValue</span><span style='color:rgba(255,255,255,1)'>());</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_temp<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(255,165,0,1)'>"array"</span><span style='color:rgba(255,255,255,1)'>][</span><span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>]);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_temp<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(255,165,0,1)'>"array"</span><span style='color:rgba(255,255,255,1)'>][</span><span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>]</span><span style='color:rgba(219,112,147,1)'>.GetValue</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(100,149,237,1)'>long</span>><span style='color:rgba(255,255,255,1)'>());</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,165,0,1)'>"this is string"</span>
<span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>this is</span> <span style='color:rgba(100,149,237,1)'>string</span>
<span class='span_code_line'></span><span style='color:rgba(255,165,0,1)'>"2"</span>
<span class='span_code_line'></span><span style='color:rgba(144,238,144,1)'>2</span></pre>
</div>
<div><h2 class='h_option anchor_point' name='a_m'>object -&gt; string</h2></div>
<p>By the above example maybe you already know how to convert an object to <span class='mark'>string</span>, by <span class='mark'>STJson.FromObject(object).ToString(+n)</span>, but is it possible that it actually doesn't need to be so troublesome? For example: <span class='mark'>STJson.Serialize(+n)</span> will do?</p>
<p>In fact <span class='mark'>STJson.Serialize(+n)</span> would be more efficient because it converts the object directly to a string, rather than converting it to <span class='mark'>STJson</span> and then to a string.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.Serialize</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(255,255,255,1)'>{</span> key <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(255,165,0,1)'>"this is test"</span> <span style='color:rgba(255,255,255,1)'>}));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span><span style='color:rgba(255,165,0,1)'>"key"</span><span style='color:rgba(255,255,255,1)'>:</span><span style='color:rgba(255,165,0,1)'>"this is test"</span><span style='color:rgba(255,255,255,1)'>}</span></pre>
</div>
<p>Of course you can have a more friendly output format:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.Serialize</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(255,255,255,1)'>{</span> key <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(255,165,0,1)'>"this is test"</span> <span style='color:rgba(255,255,255,1)'>},</span> <span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"key"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"this is test"</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>}</span></pre>
</div>
<p>In fact formatting the output is done by calling the static function <span class='mark'>STJson.Format(+n)</span>. If you don't like the author's built-in formatting style, you can write a formatting function of your own. Or go modify the source file <span class='mark'>STJson.Statics.cs:Format(string,int)</span>.</p>
<div><h2 class='h_option anchor_point' name='a_n'>string -&gt; object</h2></div>
<p>The code doesn't actually convert <span class='mark'>string</span> to <span class='mark'>object</span> directly. It has to parse the string to make sure it's a properly formatted <span class='mark'>Json</span> before it does that. But by the time this is done, you'll already have an <span class='mark'>STJson</span> object. Finally, <span class='mark'>STJson</span> is converted to <span class='mark'>object</span> again.</p>
<p>So you will see the following file in the source code <span class='mark'>STLib.Json.Converter</span>:</p>
<p><span class='mark'>ObjectToSTJson.cs</span> <span class='mark'>ObjectToString.cs</span> <span class='mark'>STJsonToObject.cs</span> <span class='mark'>StringToSTJson.cs</span></p>
<p>There is no <span class='mark'>StringToObject.cs</span> file inside, and the source code of <span class='mark'>STJson.Deserialize(+n)</span> is as follows:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>public static</span> <span style='color:rgba(0,255,255,1)'>T</span> <span style='color:rgba(255,0,255,1)'>Deserialize</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(0,255,255,1)'>T</span>><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(100,149,237,1)'>string</span> strJson<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,255,255,1)'>+</span>n<span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>    <span style='color:rgba(100,149,237,1)'>var</span> json <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>StringToSTJson</span><span style='color:rgba(219,112,147,1)'>.Get</span><span style='color:rgba(255,255,255,1)'>(</span>strJson<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,255,255,1)'>+</span>n<span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>return</span> <span style='color:rgba(0,255,255,1)'>STJsonToObject</span><span style='color:rgba(219,112,147,1)'>.Get</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(0,255,255,1)'>T</span>><span style='color:rgba(255,255,255,1)'>(</span>json<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,255,255,1)'>+</span>n<span style='color:rgba(255,255,255,1)'>);
<span class='span_code_line'></span>}</span></pre>
</div>
<div><h2 class='h_option anchor_point' name='a_o'>STJsonConverter</h2></div>
<p>Although there are a lot of data type conversions built into <span class='mark'>STJson</span>, even data types that are not available are treated as <span class='mark'>object</span> for recursive processing. But sometimes the situation is not very friendly. For example:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Rectangle</span> rect <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>Rectangle</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>10</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>10</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>100</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>100</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.Serialize</span><span style='color:rgba(255,255,255,1)'>(</span>rect<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"Location"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"IsEmpty"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(30,144,255,1)'>false</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"X"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>10</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"Y"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>10</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>},</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"Size"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"IsEmpty"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(30,144,255,1)'>false</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"Width"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>100</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"Height"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>100</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>},</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"X"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>10</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"Y"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>10</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"Width"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>100</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"Height"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>100</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"Left"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>10</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"Top"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>10</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"Right"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>110</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"Bottom"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>110</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"IsEmpty"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(30,144,255,1)'>false</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>}</span></pre>
</div>
<p>Obviously, this result is too complicated because all the fields of <span class='mark'>Rectangle</span> are recursive. But what if this is the case?</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>public class</span> <span style='color:rgba(0,255,255,1)'>RectangleConverter</span> <span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(0,255,255,1)'>STJsonConverter</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>public override</span> <span style='color:rgba(100,149,237,1)'>object</span> <span style='color:rgba(255,0,255,1)'>JsonToObject</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>Type</span> t<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(0,255,255,1)'>STJson</span> json<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>ref</span> bool <span style='color:rgba(0,255,255,1)'>bProcessed</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>return new</span> <span style='color:rgba(0,255,255,1)'>Rectangle</span><span style='color:rgba(255,255,255,1)'>(</span>
<span class='span_code_line'></span>            json<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(255,165,0,1)'>"x"</span><span style='color:rgba(255,255,255,1)'>]</span><span style='color:rgba(219,112,147,1)'>.GetValue</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(100,149,237,1)'>int</span>><span style='color:rgba(255,255,255,1)'>(),</span>
<span class='span_code_line'></span>            json<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(255,165,0,1)'>"y"</span><span style='color:rgba(255,255,255,1)'>]</span><span style='color:rgba(219,112,147,1)'>.GetValue</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(100,149,237,1)'>int</span>><span style='color:rgba(255,255,255,1)'>(),</span>
<span class='span_code_line'></span>            json<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(255,165,0,1)'>"w"</span><span style='color:rgba(255,255,255,1)'>]</span><span style='color:rgba(219,112,147,1)'>.GetValue</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(100,149,237,1)'>int</span>><span style='color:rgba(255,255,255,1)'>(),</span>
<span class='span_code_line'></span>            json<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(255,165,0,1)'>"h"</span><span style='color:rgba(255,255,255,1)'>]</span><span style='color:rgba(219,112,147,1)'>.GetValue</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(100,149,237,1)'>int</span>><span style='color:rgba(255,255,255,1)'>());
<span class='span_code_line'></span>    }</span>
<span class='span_code_line'></span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>public override</span> <span style='color:rgba(0,255,255,1)'>STJson</span> <span style='color:rgba(255,0,255,1)'>ObjectToJson</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>Type</span> t<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(100,149,237,1)'>object</span> obj<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>ref</span> bool <span style='color:rgba(0,255,255,1)'>bProcessed</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>        <span style='color:rgba(0,255,255,1)'>Rectangle</span> rect <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>Rectangle</span><span style='color:rgba(255,255,255,1)'>)</span>obj<span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>return</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.New</span><span style='color:rgba(255,255,255,1)'>()</span>
<span class='span_code_line'></span>            <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"x"</span><span style='color:rgba(255,255,255,1)'>,</span> rect<span style='color:rgba(112,128,144,1)'>.X</span><span style='color:rgba(255,255,255,1)'>)</span>
<span class='span_code_line'></span>            <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"y"</span><span style='color:rgba(255,255,255,1)'>,</span> rect<span style='color:rgba(112,128,144,1)'>.Y</span><span style='color:rgba(255,255,255,1)'>)</span>
<span class='span_code_line'></span>            <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"w"</span><span style='color:rgba(255,255,255,1)'>,</span> rect<span style='color:rgba(112,128,144,1)'>.Width</span><span style='color:rgba(255,255,255,1)'>)</span>
<span class='span_code_line'></span>            <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"h"</span><span style='color:rgba(255,255,255,1)'>,</span> rect<span style='color:rgba(112,128,144,1)'>.Height</span><span style='color:rgba(255,255,255,1)'>);
<span class='span_code_line'></span>    }</span>
<span class='span_code_line'></span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>public override</span> <span style='color:rgba(100,149,237,1)'>string</span> <span style='color:rgba(255,0,255,1)'>ObjectToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>Type</span> t<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(100,149,237,1)'>object</span> obj<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>ref</span> bool <span style='color:rgba(0,255,255,1)'>bProcessed</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>        <span style='color:rgba(0,255,0,1)'>//return "{\"x\":" + ... + "}"</span>
<span class='span_code_line'></span>        <span style='color:rgba(100,149,237,1)'>var</span> json <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>this</span><span style='color:rgba(219,112,147,1)'>.ObjectToJson</span><span style='color:rgba(255,255,255,1)'>(</span>t<span style='color:rgba(255,255,255,1)'>,</span> obj<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>ref</span> bProcessed<span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>if</span> <span style='color:rgba(255,255,255,1)'>(</span>bProcessed<span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>            <span style='color:rgba(30,144,255,1)'>return</span> json<span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>();
<span class='span_code_line'></span>        }</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>return null</span><span style='color:rgba(255,255,255,1)'>;
<span class='span_code_line'></span>    }
<span class='span_code_line'></span>}</span>
<span class='span_code_line'></span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Rectangle</span> rect <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>Rectangle</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>10</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>10</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>100</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>100</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.AddCustomConverter</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(100,149,237,1)'>typeof</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>Rectangle</span><span style='color:rgba(255,255,255,1)'>),</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>RectangleConverter</span><span style='color:rgba(255,255,255,1)'>());</span>
<span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>string</span> strResult <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.Serialize</span><span style='color:rgba(255,255,255,1)'>(</span>rect<span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>strResult<span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>rect <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.Deserialize</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(0,255,255,1)'>Rectangle</span>><span style='color:rgba(255,255,255,1)'>(</span>strResult<span style='color:rgba(219,112,147,1)'>.Replace</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"100"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"200"</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>rect<span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span><span style='color:rgba(255,165,0,1)'>"x"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>10</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(255,165,0,1)'>"y"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>10</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(255,165,0,1)'>"w"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>100</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(255,165,0,1)'>"h"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>100</span><span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>{</span>X<span style='color:rgba(255,255,255,1)'>=</span><span style='color:rgba(144,238,144,1)'>10</span><span style='color:rgba(255,255,255,1)'>,</span>Y<span style='color:rgba(255,255,255,1)'>=</span><span style='color:rgba(144,238,144,1)'>10</span><span style='color:rgba(255,255,255,1)'>,</span>Width<span style='color:rgba(255,255,255,1)'>=</span><span style='color:rgba(144,238,144,1)'>200</span><span style='color:rgba(255,255,255,1)'>,</span>Height<span style='color:rgba(255,255,255,1)'>=</span><span style='color:rgba(144,238,144,1)'>200</span><span style='color:rgba(255,255,255,1)'>}</span></pre>
</div>
<div class='div_hightlight' style='background-color:goldenrod;color:black'>
<p>where <span class='mark'>bProcessed</span> is passed in as <span class='mark'>true</span> by default, and the default processing is used when the upper-level function gets <span class='mark'>false</span>.</p>
</div>
<p>The <span class='mark'>STJsonConverter</span> provides the <span class='mark'>Attribute</span> class, which can also be used to tag object attributes.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>public class</span> <span style='color:rgba(0,255,255,1)'>Test</span><span style='color:rgba(255,255,255,1)'>{
<span class='span_code_line'></span>    [</span><span style='color:rgba(0,255,255,1)'>STJsonConverter</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(30,144,255,1)'>typeof</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>RectangleConverter</span><span style='color:rgba(255,255,255,1)'>))]</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>public</span> <span style='color:rgba(0,255,255,1)'>Rectangle</span> Rect<span style='color:rgba(255,255,255,1)'>{</span><span style='color:rgba(30,144,255,1)'>get</span><span style='color:rgba(255,255,255,1)'>;</span> <span style='color:rgba(30,144,255,1)'>set</span><span style='color:rgba(255,255,255,1)'>;}
<span class='span_code_line'></span>}</span></pre>
</div>
<span style='display:block'><span class='span_code_title'>STJsonConverter.cs</span></span>
<div class='div_code title'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>public abstract class</span> <span style='color:rgba(0,255,255,1)'>STJsonConverter</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>public virtual</span> <span style='color:rgba(0,255,255,1)'>STJson</span> <span style='color:rgba(255,0,255,1)'>ObjectToJson</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>Type</span> t<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(100,149,237,1)'>object</span> obj<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>ref</span> bool <span style='color:rgba(0,255,255,1)'>bProcessed</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>        bProcessed <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>false</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>return null</span><span style='color:rgba(255,255,255,1)'>;
<span class='span_code_line'></span>    }</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>public virtual</span> <span style='color:rgba(100,149,237,1)'>string</span> <span style='color:rgba(255,0,255,1)'>ObjectToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>Type</span> t<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(100,149,237,1)'>object</span> obj<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>ref</span> bool <span style='color:rgba(0,255,255,1)'>bProcessed</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>        bProcessed <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>false</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>return null</span><span style='color:rgba(255,255,255,1)'>;
<span class='span_code_line'></span>    }</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>public virtual</span> <span style='color:rgba(100,149,237,1)'>object</span> <span style='color:rgba(255,0,255,1)'>JsonToObject</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>Type</span> t<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(0,255,255,1)'>STJson</span> json<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>ref</span> bool <span style='color:rgba(0,255,255,1)'>bProcessed</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>        bProcessed <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>false</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>return null</span><span style='color:rgba(255,255,255,1)'>;
<span class='span_code_line'></span>    }
<span class='span_code_line'></span>}</span></pre>
</div>
<div><h2 class='h_option anchor_point' name='a_p'>STJsonAttribute</h2></div>
<p>Maybe you don't want to output all the attributes when serializing, then you can control it with <span class='mark'>STJsonAttribute</span>.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span>[<span style='color:rgba(219,112,147,1)'>STJson</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>STJsonSerilizaMode</span><span style='color:rgba(112,128,144,1)'>.Include</span><span style='color:rgba(255,255,255,1)'>)]</span>    <span style='color:rgba(0,255,0,1)'>// optional</span>
<span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>public class</span> <span style='color:rgba(0,255,255,1)'>Student</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{
<span class='span_code_line'></span>    [</span><span style='color:rgba(0,255,255,1)'>STJsonProperty</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"test_name"</span><span style='color:rgba(255,255,255,1)'>)]</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>public</span> <span style='color:rgba(100,149,237,1)'>string</span> Name<span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>public</span> <span style='color:rgba(100,149,237,1)'>int</span> Age<span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>public</span> <span style='color:rgba(0,255,255,1)'>Gender</span> Gender<span style='color:rgba(255,255,255,1)'>;
<span class='span_code_line'></span>    [</span>STJsonProperty<span style='color:rgba(255,255,255,1)'>]</span>                        <span style='color:rgba(0,255,0,1)'>// optional</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>public</span> <span style='color:rgba(0,255,255,1)'>List</span><<span style='color:rgba(100,149,237,1)'>string</span>> Hobby<span style='color:rgba(255,255,255,1)'>;
<span class='span_code_line'></span>}</span>
<span class='span_code_line'></span>
<span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>public enum</span> <span style='color:rgba(0,255,255,1)'>Gender</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    Male<span style='color:rgba(255,255,255,1)'>,</span> Female
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>}</span>
<span class='span_code_line'></span>
<span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> stu <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>Student</span><span style='color:rgba(255,255,255,1)'>() {</span>
<span class='span_code_line'></span>    Name <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(255,165,0,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    Age <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(144,238,144,1)'>100</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    Gender <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>Gender</span><span style='color:rgba(112,128,144,1)'>.Male</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    Hobby <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>List</span><<span style='color:rgba(100,149,237,1)'>string</span>><span style='color:rgba(255,255,255,1)'>() {</span> <span style='color:rgba(255,165,0,1)'>"Game"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"Sing"</span> <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>};</span>
<span class='span_code_line'></span>
<span class='span_code_line'></span>str <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.Serialize</span><span style='color:rgba(255,255,255,1)'>(</span>stu<span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>str<span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span><span style='color:rgba(255,165,0,1)'>"test_name"</span><span style='color:rgba(255,255,255,1)'>:</span><span style='color:rgba(255,165,0,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(255,165,0,1)'>"Hobby"</span><span style='color:rgba(255,255,255,1)'>:</span><span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(255,165,0,1)'>"Cooking"</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(255,165,0,1)'>"Sports"</span><span style='color:rgba(255,255,255,1)'>]}</span></pre>
</div>
<div><h2 class='h_option anchor_point' name='a_q'>STJsonSetting</h2></div>
<p><span class='mark'>STJsonSetting</span> is used to add some personalized settings to the serialization or deserialization. Originally the settings were global. But with the increase of some setting items, the author thinks that the global setting is too sticky, so the independent <span class='mark'>STJsonSetting</span> is used for decoupling. At the same time the independent setting class can also facilitate the subsequent version of the feature expansion, of course the probability of subsequent versions is not very large. Unless the author does not want to be a salty fish.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> stu <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>Student</span><span style='color:rgba(255,255,255,1)'>() {</span>
<span class='span_code_line'></span>    Name <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(255,165,0,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    Age <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(144,238,144,1)'>100</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    Gender <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>Gender</span><span style='color:rgba(112,128,144,1)'>.Male</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    Hobby <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>List</span><<span style='color:rgba(100,149,237,1)'>string</span>><span style='color:rgba(255,255,255,1)'>() {</span> <span style='color:rgba(255,165,0,1)'>"Game"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"Sing"</span> <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>};</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>STJsonSetting</span> setting <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJsonSetting</span><span style='color:rgba(255,255,255,1)'>();</span>
<span class='span_code_line'></span>setting<span style='color:rgba(112,128,144,1)'>.EnumUseNumber</span> <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>setting<span style='color:rgba(112,128,144,1)'>.IgnoreAttribute</span> <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>setting<span style='color:rgba(112,128,144,1)'>.Mode</span> <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>STJsonSettingKeyMode</span><span style='color:rgba(112,128,144,1)'>.Exclude</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>setting<span style='color:rgba(112,128,144,1)'>.KeyList</span><span style='color:rgba(219,112,147,1)'>.Add</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"Age"</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>str <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.Serialize</span><span style='color:rgba(255,255,255,1)'>(</span>stu<span style='color:rgba(255,255,255,1)'>,</span> setting<span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.Format</span><span style='color:rgba(255,255,255,1)'>(</span>str<span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.Deserialize</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(0,255,255,1)'>Student</span>><span style='color:rgba(255,255,255,1)'>(</span>str<span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"test_name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"Gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"Hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"Game"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"Sing"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>}</span></pre>
</div>
<div class='div_hightlight' style='background-color:pink;color:black'>
<p>The priority of <span class='mark'>Attribute</span> is greater than that of <span class='mark'>STJsonSetting</span>.</p>
</div>
<div><h2 class='h_option anchor_point' name='a_r'>json_src</h2></div>
<p>In the next tutorials we will use some test data, which are as follows:</p>
<span style='display:block'><span class='span_code_title'>test.json</span></span>
<div class='div_code title'>
<pre class='pre_code'><span class='span_code_line'></span><span>[<span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>16</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"cooking"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"sing"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>},{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tony"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>16</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"game"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"dance"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>},{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Andy"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>20</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"draw"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"sing"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>},{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Kun"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>26</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"sing"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"dance"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"rap"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"basketball"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>}]</span></pre>
</div>
<p>To load it into the program:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> json_src <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.Deserialize</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>System</span><span style='color:rgba(112,128,144,1)'>.IO.File</span><span style='color:rgba(219,112,147,1)'>.ReadAllText</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"./test.json"</span><span style='color:rgba(255,255,255,1)'>));</span></pre>
</div>
<div class='div_hightlight' style='background-color:pink;color:black'>
<p>The appearance of <span class='mark'>json_src</span> in the subsequent cases is the above object.</p>
</div>
<h1 class='h_title anchor_point' name='a_s'>STJsonPath</h1>
<p>In the source code <span class='mark'>STJsonExtension.cs</span> the functionality of <span class='mark'>STJson</span> is extended and some of the functionality of <span class='mark'>STJsonPath</span> is integrated in it. So there is no dependency on <span class='mark'>STJsonPath</span> in the original code of <span class='mark'>STJson</span>, and <span class='mark'>STJson</span> can be used independently. But <span class='mark'>STJsonPath</span>, as a helper class of <span class='mark'>STJson</span>, needs to depend on <span class='mark'>STJson</span>.</p>
<div><h2 class='h_option anchor_point' name='a_t'>Selector</h2></div>
<div class='div_table'>
<table>
<tr><th>token</th><th>note</th></tr>
<tr><td>$</td><td>The root selector, which can be treated as representing the root object.</td></tr>
<tr class='tr_hight'><td>@</td><td>current element selector, which refers to the currently traversed element during traversal.</td></tr>
<tr><td>*</td><td>Wildcard, indicating that it can represent any node.</td></tr>
<tr class='tr_hight'><td>. &lt;name&gt;</td><td>Child node selector, specifying the <span class='mark'>key</span> of the child node.</td></tr>
<tr><td>... </td><td>depth selector, indicating that it can be any path.</td></tr>
<tr class='tr_hight'><td>['&lt;name&gt;'(,'&lt;name&gt;')]</td><td>List selector, specifying the set of <span class='mark'>key</span>s of the child nodes.</td></tr>
<tr><td>[&lt;number&gt;(,(number))]</td><td>List selector, specifies the set of <span class='mark'>index</span> of the child nodes.</td></tr>
<tr class='tr_hight'><td>[start:end:step]</td><td>Slice selector specifying the index interval.</td></tr>
<tr><td>[(&lt;expression&gt;)]</td><td>expression selector for entering an arithmetic expression and continuing down the index with the result.</td></tr>
<tr class='tr_hight'><td>[? (&lt;expression&gt;)]</td><td>expression selector, used to enter an arithmetic expression and convert the result to a boolean value to decide whether to continue the selection.</td></tr>
</table>
</div>
<div><h2 class='h_option anchor_point' name='a_u'>How to use</h2></div>
<p>An <span class='mark'>STJsonPath</span> can be constructed by:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>// var jp = new STJsonPath("$[0]name");
<span class='span_code_line'></span>// var jp = new STJsonPath("$[0].name");</span>
<span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> jp <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJsonPath</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"[0]'name'"</span><span style='color:rgba(255,255,255,1)'>);</span> <span style='color:rgba(0,255,0,1)'>// All of the above methods can be used, $ is not must.</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>jp<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(255,165,0,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>]</span></pre>
</div>
<p>Of course <span class='mark'>STJsonPath</span> is already integrated in the extension functions in <span class='mark'>STJson</span> and can be used directly by the following:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>// var jp = new STJsonPath("[0].name");
<span class='span_code_line'></span>// Console.WriteLine(json_src.Select(jp));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"[0].name"</span><span style='color:rgba(255,255,255,1)'>));</span> <span style='color:rgba(0,255,0,1)'>// Internal dynamic construction of STJsonPath
<span class='span_code_line'></span>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(255,165,0,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>]</span></pre>
</div>
<div class='div_hightlight' style='background-color:goldenrod;color:black'>
<p><span class='mark'>STJsonPath</span> returns data as an array, and its return value is <span class='mark'>STJson</span> instead of <span class='mark'>List&lt;STJson&gt;</span>, <span class='mark'>STJson</span> can also be an array object.</p>
<p>The beginning of <span class='mark'>$</span> is not required for <span class='mark'>STJsonPath</span> and the beginning <span class='mark'>$</span> or <span class='mark'>@</span> is removed internally, <span class='mark'>$</span><span class='mark'>@</span> is only used as a variable of the object in the expression.</p>
</div>
<div class='div_hightlight' style='background-color:pink;color:black'>
<p>The return value of a selector in an expression returns only the first result selected. This is not an array list, as will be explained later.</p>
</div>
<p>The use of <span class='mark'>'</span> or <span class='mark'>"</span> is allowed in <span class='mark'>STJsonPath</span>, for example: <span class='mark'>'a.b'</span> <span class='mark'>"a.b"</span> <span class='mark'>STJsonPath</span> will treat it as a separate entity. Instead of two. Listing such as <span class='mark'>Json</span> as follows:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span>{
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"a.b"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"this is a test"</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>}</span></pre>
</div>
<p>It is obvious that the data cannot be obtained by <span class='mark'>Select("a.b")</span>, you need to pass <span class='mark'>Select("'a.b'")</span>.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>string</span> strTemp <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(255,165,0,1)'>"{\"a.b\": \"this is a test\"}"</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> json_temp <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.Deserialize</span><span style='color:rgba(255,255,255,1)'>(</span>strTemp<span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_temp<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"a.b"</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_temp<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"'a.b'"</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[]
<span class='span_code_line'></span>[</span><span style='color:rgba(255,165,0,1)'>"this is a test"</span><span style='color:rgba(255,255,255,1)'>]</span></pre>
</div>
<p>Support for <span class='mark'>\</span> in strings for escaping:<span class='mark'>\r</span><span class='mark'>\n</span><span class='mark'>\t</span><span class='mark'>\f</span><span class='mark'>\b</span><span class='mark'>\a</span><span class='mark'>\v</span><span class='mark'>\0</span><span class='mark'>\x..</span><span class='mark'>\u...</span><span class='mark'>\.</span></p>
<div><h2 class='h_option anchor_point' name='a_v'>Wildcard character</h2></div>
<p>Wildcards can represent any node of the current level. Gets the names of all people.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"*.name"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>    <span style='color:rgba(0,255,255,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"Tony"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"Andy"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"Kun"</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>]</span></pre>
</div>
<div><h2 class='h_option anchor_point' name='a_w'>Depth selector</h2></div>
<p>Depth selectors are similar to wildcards, but depth selectors can be at any level.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"..name"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>    <span style='color:rgba(0,255,255,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"Tony"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"Andy"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"Kun"</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>]</span></pre>
</div>
<div><h2 class='h_option anchor_point' name='a_x'>List selector</h2></div>
<p>List selectors support both <span class='mark'>int</span> and <span class='mark'>string</span>. Although two list selectors are listed in the table of <span class='mark'>selectors</span> above, there is only one list selector in <span class='mark'>STJsonPath</span>, and they can be mixed, for example, the following uses are both legal:</p>
<ul>
<li><span class='mark'>[0, 1, 2, 3]</span></li>
<li><span class='mark'>['key_1', 'key_2', key_3]</span></li>
<li><span class='mark'>[0, 'key_1', 1, 'key_2', 2, key_3]</span></li>
</ul>
<p><span class='mark'>STJsonPath</span> will automatically split into two list selectors internally and determine which list selector to use by judging <span class='mark'>STJsonValueType</span>. The internal implementation code is as follows:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>case</span> <span style='color:rgba(0,255,255,1)'>STJsonPathItem</span><span style='color:rgba(112,128,144,1)'>.ItemType.List</span><span style='color:rgba(255,255,255,1)'>:</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>if</span> <span style='color:rgba(255,255,255,1)'>(</span>jsonCurrent<span style='color:rgba(112,128,144,1)'>.ValueType</span> <span style='color:rgba(255,255,255,1)'>==</span> <span style='color:rgba(0,255,255,1)'>STJsonValueType</span><span style='color:rgba(112,128,144,1)'>.Object</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>foreach</span> <span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(100,149,237,1)'>var</span> v <span style='color:rgba(30,144,255,1)'>in</span> item<span style='color:rgba(112,128,144,1)'>.Keys</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>            <span style='color:rgba(30,144,255,1)'>if</span> <span style='color:rgba(255,255,255,1)'>(</span>jsonCurrent<span style='color:rgba(255,255,255,1)'>[</span>v<span style='color:rgba(255,255,255,1)'>]</span> <span style='color:rgba(255,255,255,1)'>==</span> <span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>                <span style='color:rgba(30,144,255,1)'>continue</span><span style='color:rgba(255,255,255,1)'>;
<span class='span_code_line'></span>            }</span>
<span class='span_code_line'></span>            <span style='color:rgba(0,255,0,1)'>// ...</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>    }</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>if</span> <span style='color:rgba(255,255,255,1)'>(</span>jsonCurrent<span style='color:rgba(112,128,144,1)'>.ValueType</span> <span style='color:rgba(255,255,255,1)'>==</span> <span style='color:rgba(0,255,255,1)'>STJsonValueType</span><span style='color:rgba(112,128,144,1)'>.Array</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>foreach</span> <span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(100,149,237,1)'>var</span> v <span style='color:rgba(30,144,255,1)'>in</span> item<span style='color:rgba(112,128,144,1)'>.Indices</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>            nIndexSliceL <span style='color:rgba(255,255,255,1)'>=</span> v<span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>            <span style='color:rgba(30,144,255,1)'>if</span> <span style='color:rgba(255,255,255,1)'>(</span>nIndexSliceL <span style='color:rgba(255,255,255,1)'><</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>)</span> nIndexSliceL <span style='color:rgba(255,255,255,1)'>=</span> jsonCurrent<span style='color:rgba(112,128,144,1)'>.Count</span> <span style='color:rgba(255,255,255,1)'>+</span> nIndexSliceL<span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>            <span style='color:rgba(30,144,255,1)'>if</span> <span style='color:rgba(255,255,255,1)'>(</span>nIndexSliceL <span style='color:rgba(255,255,255,1)'><</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>)</span> <span style='color:rgba(30,144,255,1)'>continue</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>            <span style='color:rgba(30,144,255,1)'>if</span> <span style='color:rgba(255,255,255,1)'>(</span>nIndexSliceL <span style='color:rgba(255,255,255,1)'>>=</span> jsonCurrent<span style='color:rgba(112,128,144,1)'>.Count</span><span style='color:rgba(255,255,255,1)'>)</span> <span style='color:rgba(30,144,255,1)'>continue</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>            <span style='color:rgba(0,255,0,1)'>// ...</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>    }</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>break</span><span style='color:rgba(255,255,255,1)'>;</span></pre>
</div>
<p>Selects the elements with index <span class='mark'>0</span> and <span class='mark'>2</span>.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"[0,2]"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>    {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>16</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"cooking"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"sing"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }, {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Andy"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>20</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"draw"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"sing"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }
<span class='span_code_line'></span>]</span></pre>
</div>
<p>Negative numbers can be used for <span class='mark'>int</span> indexes, e.g. <span class='mark'>-1</span> means get the last element. When <span class='mark'>STJsonPath</span> detects a negative number it will execute <span class='mark'>STJson.Count - n</span> to use the result as index.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>//Console.WriteLine(json_src.Select("-1").ToString(4));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"[-1]"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>    {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Kun"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>26</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"sing"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"dance"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"rap"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"basketball"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }
<span class='span_code_line'></span>]</span></pre>
</div>
<div><h2 class='h_option anchor_point' name='a_y'>Slice selector</h2></div>
<p>The slice selector is used to select a fragment in an array. The default value of the slice selector is <span class='mark'>[0:-1:1]</span>, which is implemented inside the slice selector as follows:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>case</span> <span style='color:rgba(0,255,255,1)'>STJsonPathItem</span><span style='color:rgba(112,128,144,1)'>.ItemType.Slice</span><span style='color:rgba(255,255,255,1)'>:</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>if</span> <span style='color:rgba(255,255,255,1)'>(</span>jsonCurrent<span style='color:rgba(112,128,144,1)'>.ValueType</span> <span style='color:rgba(255,255,255,1)'>!=</span> <span style='color:rgba(0,255,255,1)'>STJsonValueType</span><span style='color:rgba(112,128,144,1)'>.Array</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>return</span><span style='color:rgba(255,255,255,1)'>;
<span class='span_code_line'></span>    }</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>if</span> <span style='color:rgba(255,255,255,1)'>(</span>nIndexSliceL <span style='color:rgba(255,255,255,1)'><</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>)</span> nIndexSliceL <span style='color:rgba(255,255,255,1)'>=</span> jsonCurrent<span style='color:rgba(112,128,144,1)'>.Count</span> <span style='color:rgba(255,255,255,1)'>+</span> nIndexSliceL<span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>if</span> <span style='color:rgba(255,255,255,1)'>(</span>nIndexSliceR <span style='color:rgba(255,255,255,1)'><</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>)</span> nIndexSliceR <span style='color:rgba(255,255,255,1)'>=</span> jsonCurrent<span style='color:rgba(112,128,144,1)'>.Count</span> <span style='color:rgba(255,255,255,1)'>+</span> nIndexSliceR<span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>if</span> <span style='color:rgba(255,255,255,1)'>(</span>nIndexSliceL <span style='color:rgba(255,255,255,1)'><</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>)</span> nIndexSliceL <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>else if</span> <span style='color:rgba(255,255,255,1)'>(</span>nIndexSliceL <span style='color:rgba(255,255,255,1)'>>=</span> jsonCurrent<span style='color:rgba(112,128,144,1)'>.Count</span><span style='color:rgba(255,255,255,1)'>)</span> nIndexSliceL <span style='color:rgba(255,255,255,1)'>=</span> jsonCurrent<span style='color:rgba(112,128,144,1)'>.Count</span> <span style='color:rgba(255,255,255,1)'>-</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>if</span> <span style='color:rgba(255,255,255,1)'>(</span>nIndexSliceR <span style='color:rgba(255,255,255,1)'><</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>)</span> nIndexSliceR <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>else if</span> <span style='color:rgba(255,255,255,1)'>(</span>nIndexSliceR <span style='color:rgba(255,255,255,1)'>>=</span> jsonCurrent<span style='color:rgba(112,128,144,1)'>.Count</span><span style='color:rgba(255,255,255,1)'>)</span> nIndexSliceR <span style='color:rgba(255,255,255,1)'>=</span> jsonCurrent<span style='color:rgba(112,128,144,1)'>.Count</span> <span style='color:rgba(255,255,255,1)'>-</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>if</span> <span style='color:rgba(255,255,255,1)'>(</span>nIndexSliceL <span style='color:rgba(255,255,255,1)'>></span> nIndexSliceR<span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>for</span> <span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(100,149,237,1)'>int</span> i <span style='color:rgba(255,255,255,1)'>=</span> nIndexSliceL<span style='color:rgba(255,255,255,1)'>;</span> i <span style='color:rgba(255,255,255,1)'>>=</span> nIndexSliceR<span style='color:rgba(255,255,255,1)'>;</span> i <span style='color:rgba(255,255,255,1)'>-=</span> item<span style='color:rgba(112,128,144,1)'>.Step</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>            <span style='color:rgba(0,255,0,1)'>// ...</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>    }</span> <span style='color:rgba(30,144,255,1)'>else</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>for</span> <span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(100,149,237,1)'>int</span> i <span style='color:rgba(255,255,255,1)'>=</span> nIndexSliceL<span style='color:rgba(255,255,255,1)'>;</span> i <span style='color:rgba(255,255,255,1)'><=</span> nIndexSliceR<span style='color:rgba(255,255,255,1)'>;</span> i <span style='color:rgba(255,255,255,1)'>+=</span> item<span style='color:rgba(112,128,144,1)'>.Step</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>            <span style='color:rgba(0,255,0,1)'>// ...</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>    }</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>break</span><span style='color:rgba(255,255,255,1)'>;</span></pre>
</div>
<p>So the three values in the slice are equivalent to the three conditions in the <span class='mark'>for</span> loop, so the principle and effect will not be explained.</p>
<div class='div_table'>
<table>
<tr><th>expression</th><th>range</th><th>note</th></tr>
<tr><td>[::]</td><td>0 &lt;= R &lt;= (OBJ).length - 1</td><td>equivalent to <span class='mark'>*</span>.</td></tr>
<tr class='tr_hight'><td>[5:]</td><td>5 &lt;= R &lt;= {OBJ}.length - 1</td><td>Gets all elements starting with the <span class='mark'>6th</span> element.</td></tr>
<tr><td>[-1:0]</td><td>{OBJ}.length - 1 &gt;= R &gt;= 0</td><td>Get the data in reverse order.</td></tr>
<tr class='tr_hight'><td>[0::2]</td><td>0 &lt;= R &lt;= {OBJ}.length - 1</td><td>Fetch data in order and one data interval apart.</td></tr>
</table>
</div>
<div class='div_hightlight' style='background-color:goldenrod;color:black'>
<p>At least one <span class='mark'>:</span> appears in the slice selector and <span class='mark'>step</span> is greater than 0, otherwise it will get an exception.</p>
</div>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"[-1:]"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>    {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Kun"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>26</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"sing"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"dance"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"rap"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"basketball"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }
<span class='span_code_line'></span>]</span></pre>
</div>
<div><h2 class='h_option anchor_point' name='a_z'>Expression</h2></div>
<p>The following operators can be supported in <span class='mark'>[?()]</span>, with increasing priority from top to bottom.</p>
<hr/>
<ul>
<li><span class='mark'>&amp;&amp;</span> <span class='mark'>||</span></li>
<li><span class='mark'>&lt;</span> <span class='mark'>&lt;=</span> <span class='mark'>&gt;</span> <span class='mark'>&gt;=</span> <span class='mark'>==</span> <span class='mark'>!=</span> <span class='mark'>re</span></li>
<li><span class='mark'>&amp;</span> <span class='mark'>|</span> <span class='mark'>&lt;&lt;</span> <span class='mark'>&gt;&gt;</span> <span class='mark'>^</span> <span class='mark'>~</span></li>
<li><span class='mark'>+</span> <span class='mark'>-</span></li>
<li><span class='mark'>*</span> <span class='mark'>/</span> <span class='mark'>%</span></li>
<li><span class='mark'>in</span> <span class='mark'>nin</span> <span class='mark'>anyof</span></li>
<li><span class='mark'>!</span></li>
</ul>
<div class='div_table'>
<table>
<tr><th>operator</th><th>note</th><th>e.g</th></tr>
<tr><td>re</td><td>Regular expressions. </td><td>[?(@.name re 'un')]</td></tr>
<tr class='tr_hight'><td>in</td><td>The left value or array is contained in the right array. </td><td>[?(@.age in [16,20])]</td></tr>
<tr><td>nin</td><td>The value or array on the left is not contained in the array on the right. </td><td>[?(@.hobby nin ['sing','draw'])]</td></tr>
<tr class='tr_hight'><td>anyof</td><td>The intersection of the value or array on the left and the array on the right exists. </td><td>[?(@.hobby anyof ['sing','draw'])]</td></tr>
</table>
</div>
<p>Expressions have two modes:</p>
<ul>
<li><span class='mark'>[[? (&lt;expression&gt;)</span> - Filter expression that computes a boolean value and determines whether to continue the match.</li>
<li><span class='mark'>[(&lt;expression&gt;)</span> - A general expression that computes a value and continues the match with the value as an index.</li>
</ul>
<div><h2 class='h_option anchor_point' name='b_a'>Filter expression</h2></div>
<p>Check the elements of <span class='mark'>name</span> that contain the letters <span class='mark'>ku</span>:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>//Console.WriteLine(json_src.Select("*.[?(@.name == 'kun')]").ToString(4));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"*.[?(@.name re '(?i)ku')]"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>    {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Kun"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>26</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"sing"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"dance"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"rap"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"basketball"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }
<span class='span_code_line'></span>]</span></pre>
</div>
<p>The <span class='mark'>i</span> in <span class='mark'>(?i)</span> means case is ignored, and its regular expression is based on the <span class='mark'>Regex</span> in <span class='mark'>. </span>(?...) <span class='mark'> starts with </span>(?...)` to set the matching pattern. As for the matching pattern, please check the related information by yourself.</p>
<p>Check the elements of <span class='mark'>hobby</span> that do not contain <span class='mark'>sing</span> and <span class='mark'>swing</span>:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"*.[?(@.hobby nin ['sing','draw'])]"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>    {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tony"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>16</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"game"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"dance"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }
<span class='span_code_line'></span>]</span></pre>
</div>
<div><h2 class='h_option anchor_point' name='b_b'>General expression</h2></div>
<p>The general expression will continue matching the result as part of <span class='mark'>STJsonPath</span>.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"*.[('na' + 'me')]"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>    <span style='color:rgba(0,255,255,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"Tony"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"Andy"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"Kun"</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>]</span></pre>
</div>
<p>In <span class='mark'>[('na' + 'me')]</span> the result of <span class='mark'>'na' + 'me'</span> is <span class='mark'>'name'</span> and will use this value as an index, so the above effect is equivalent to <span class='mark'>*.name</span>, but of course the return value can also be a collection.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"*.[(['na' + 'me', 'age', 0, 1 + 1])]"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>    <span style='color:rgba(0,255,255,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>16</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"Tony"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>16</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"Andy"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>20</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"Kun"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>26</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>]</span></pre>
</div>
<p>The result of the above expression settles on the value <span class='mark'>['name', 'age', 0, 2]</span>. But obviously <span class='mark'>0</span> and <span class='mark'>2</span> will not do anything, because the second level data object is not an array.</p>
<p>The above expression is equivalent to <span class='mark'>*. ['name', 'age', 0, 2]</span>. If you replace the above with the third level you will get the following result.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"*.*.[(['na' + 'me', 'age', 0, 1 + 1])]"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>    <span style='color:rgba(0,255,255,1)'>"cooking"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"game"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"draw"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"sing"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"rap"</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>]</span></pre>
</div>
<p>You can see that <span class='mark'>'name'</span> and <span class='mark'>'age'</span> are not valid for <span class='mark'>hobby</span> because <span class='mark'>hobby</span> is an array.</p>
<div><h2 class='h_option anchor_point' name='b_c'>Test expression</h2></div>
<p>The author provides a static test function <span class='mark'>TestExpression()</span> that can be used to debug the expression. If there is something you don't understand, test it and you will see the process and the result.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>STJsonPath</span><span style='color:rgba(219,112,147,1)'>.TestExpression</span><span style='color:rgba(255,255,255,1)'>(</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>,</span>           <span style='color:rgba(0,255,0,1)'>// [STJson] is used to replace the $ that appears in the expression.</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>,</span>           <span style='color:rgba(0,255,0,1)'>// [STJson] is used to replace the @ that appears in the expression.</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"1+2+3"</span>         <span style='color:rgba(0,255,0,1)'>// Expression text.</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"expression"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"parsed"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"{1 + 2 + 3}"</span><span style='color:rgba(255,255,255,1)'>,</span>        <span style='color:rgba(0,255,0,1)'>// The formatted text {} means that this part needs to be executed separately e.g. [1, {1+1}, 3].</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"polish"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"1"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"2"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>" + "</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"3"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>" + "</span> <span style='color:rgba(0,255,0,1)'>// Inverse Polish expressions.</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>],</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"steps"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>                      <span style='color:rgba(0,255,0,1)'>// The excute steps</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"excute"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"operator"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"+"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"get_left_token"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>     <span style='color:rgba(0,255,0,1)'>// Computes the value of the element to the left of the operator, the left side of the expression may also be an expression.</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"parsed"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"1"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"result"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"value_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Long"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"text"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"1"</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>            },</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"get_right_token"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"parsed"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"2"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"result"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"value_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Long"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"text"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"2"</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>            },</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"result"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>             <span style='color:rgba(0,255,0,1)'>// The result of this step execution.</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"value_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Long"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"text"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"3"</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>        }, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"excute"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"operator"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"+"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"get_left_token"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>     <span style='color:rgba(0,255,0,1)'>// In this case, the element to the left of the operator is the result of the calculation of the previous step.</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"parsed"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"3"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"result"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"value_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Long"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"text"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"3"</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>            },</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"get_right_token"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"parsed"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"3"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"result"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"value_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Long"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"text"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"3"</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>            },</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"result"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"value_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Long"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"text"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"6"</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>        }
<span class='span_code_line'></span>    ],</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"check_result"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>               <span style='color:rgba(0,255,0,1)'>// Clears the Polish expression data stack and determines the final output.</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"parsed"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"6"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"result"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Long"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"text"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"6"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>    },</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"return"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>                     <span style='color:rgba(0,255,0,1)'>// The final return value.</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"value_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Long"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"text"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"6"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"bool"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(30,144,255,1)'>true</span>                <span style='color:rgba(0,255,0,1)'>// Converts to true if used as a Boolean expression.</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>}</span></pre>
</div>
<p>If the process is not important and you simply want to see the results of the execution.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>STJsonPath</span><span style='color:rgba(219,112,147,1)'>.TestExpression</span><span style='color:rgba(255,255,255,1)'>(</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>,</span>           <span style='color:rgba(0,255,0,1)'>// [STJson] is used to replace the $ that appears in the expression.</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>,</span>           <span style='color:rgba(0,255,0,1)'>// [STJson] is used to replace the @ that appears in the expression.</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"1+2+3"</span>         <span style='color:rgba(0,255,0,1)'>// Expression text.</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.SelectFirst</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"return"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"return"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>                     <span style='color:rgba(0,255,0,1)'>// The final return value.</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"value_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Long"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"text"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"6"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"bool"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(30,144,255,1)'>true</span>                <span style='color:rgba(0,255,0,1)'>// // Converts to true if used as a Boolean expression.</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>}</span></pre>
</div>
<div><h2 class='h_option anchor_point' name='b_d'>Build-In functions</h2></div>
<div class='div_table'>
<table>
<tr><th>return</th><th>signature</th><th>note</th></tr>
<tr><td>string</td><td>typeof(+n)</td><td>Get the data type.</td></tr>
<tr class='tr_hight'><td>string</td><td>str(+n)</td><td>Convert to string.</td></tr>
<tr><td>string</td><td>upper(+n)</td><td>Convert to uppercase.</td></tr>
<tr class='tr_hight'><td>string</td><td>lower(+n)</td><td>Convert to lowercase.</td></tr>
<tr><td>long</td><td>len(+n)</td><td>Get the length of a string or an array.</td></tr>
<tr class='tr_hight'><td>long</td><td>long(+n)</td><td>Convert to integer.</td></tr>
<tr><td>double</td><td>double(+n)</td><td>Convert to double.</td></tr>
<tr class='tr_hight'><td>long or double</td><td>abs(+n)</td><td>Get the absolute value.</td></tr>
<tr><td>long</td><td>round(+n)</td><td>Round up to round down.</td></tr>
<tr class='tr_hight'><td>long</td><td>ceil(+n)</td><td>Round up.</td></tr>
</table>
</div>
<p><span class='mark'>typeof</span> has the following return values:</p>
<p><span class='mark'>string</span> <span class='mark'>long</span> <span class='mark'>double</span> <span class='mark'>boolean</span> <span class='mark'>array</span> <span class='mark'>object</span> <span class='mark'>undefined</span></p>
<p>The above functions can be signed with the following signature:</p>
<ul>
<li>fn(object)</li>
<li>fn(object[])</li>
<li>fn(object,bool)</li>
<li>fn(object[],bool)</li>
</ul>
<p>where <span class='mark'>bool</span> indicates whether the result is expected as an array, if <span class='mark'>true</span> then the result is output as an array, and when <span class='mark'>object</span> is an array, the data in it is recursive.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>STJsonPath</span><span style='color:rgba(219,112,147,1)'>.TestExpression</span><span style='color:rgba(255,255,255,1)'>(</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"typeof([1+2+3,'abc'], false)"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.SelectFirst</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"return"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"bool"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"value_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"String"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"array"</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>}</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>// =============================================================================</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>STJsonPath</span><span style='color:rgba(219,112,147,1)'>.TestExpression</span><span style='color:rgba(255,255,255,1)'>(</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"typeof([1+2+3,'abc'], true)"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.SelectFirst</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"return"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"bool"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"value_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Array"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"items"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"long"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"string"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>}</span></pre>
</div>
<p>Different functions use different default values for the second parameter. The following are some other functions that the reader can test the effect themselves by <span class='mark'>TestExpression()</span>.</p>
<div class='div_table'>
<table>
<tr><th>return</th><th>signature</th><th>note</th></tr>
<tr><td>long or double</td><td>max(+1)</td><td>Get the maximum value.</td></tr>
<tr class='tr_hight'><td>long or double</td><td>min(+1)</td><td>Get the minimum value.</td></tr>
<tr><td>long or double</td><td>avg(+1)</td><td>Get the average.</td></tr>
<tr class='tr_hight'><td>long or double</td><td>sum(+1)</td><td>Get the summary.</td></tr>
<tr><td>string</td><td>trim(+n)</td><td>Crop the specified characters at both ends of the string.</td></tr>
<tr class='tr_hight'><td>string</td><td>trims(+n)</td><td>Cuts the character at the beginning of the string.</td></tr>
<tr><td>string</td><td>trime(+n)</td><td>Cuts the character at the end of the string.</td></tr>
<tr class='tr_hight'><td>string_array</td><td>split(+1)</td><td>split the string.</td></tr>
<tr><td>long or string</td><td>time(+n)</td><td>Get or format the timestamp.</td></tr>
</table>
</div>
<div><h2 class='h_option anchor_point' name='b_e'>Build-In functions list</h2></div>
<p>As the version is iteratively updated (if possible), the built-in functions may change at any time. The <span class='mark'>GetBuildInFunctionList()</span> allows you to view information about the built-in functions supported by the current version.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>STJsonPath</span><span style='color:rgba(219,112,147,1)'>.GetBuildInFunctionList</span><span style='color:rgba(255,255,255,1)'>()</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>    {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"typeof"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"demos"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"(object) -> typeof('abc')"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"(array,bool) -> typeof(['abc',123],true)"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    },</span>
<span class='span_code_line'></span>    ...
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>]</span></pre>
</div>
<p>The reader can test the function by following <span class='mark'>demos</span> with <span class='mark'>TestExpression()</span>.</p>
<p>Select elements whose <span class='mark'>hobby</span> length is greater than <span class='mark'>2</span>:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"..[?(len(@.hobby) > 1 + 1)]"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>    {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Kun"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>26</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"sing"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"dance"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"rap"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"basketball"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }
<span class='span_code_line'></span>]</span></pre>
</div>
<div><h2 class='h_option anchor_point' name='b_f'>Custom functions</h2></div>
<p>When providing built-in functions for expressions, the authors didn't know what kind of functions the developers expected, so they built a few and then just left them alone. There is no problem that can't be solved by writing code, yes. Let the developers write their own. But how do developers provide functions for <span class='mark'>STJsonPath</span>?</p>
<p><span class='mark'>STJsonPath.CustomFunctions</span> is a static dictionary. It is used to hold developer-defined functions. Its function signatures are as follows:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>public</span> <span style='color:rgba(0,255,255,1)'>delegate STJson</span> <span style='color:rgba(255,0,255,1)'>STJsonPathCustomFuncHander</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>STJsonPathExpFuncArg</span><span style='color:rgba(255,255,255,1)'>[]</span> args<span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>
<span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>public struct</span> <span style='color:rgba(0,255,255,1)'>STJsonPathExpFuncArg</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>public</span> <span style='color:rgba(0,255,255,1)'>STJsonPathExpFuncArgType</span> Type<span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>public</span> <span style='color:rgba(100,149,237,1)'>object</span> Value<span style='color:rgba(255,255,255,1)'>;
<span class='span_code_line'></span>}</span>
<span class='span_code_line'></span>
<span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>public enum</span> <span style='color:rgba(0,255,255,1)'>STJsonPathExpFuncArgType</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    Undefined<span style='color:rgba(255,255,255,1)'>,</span> Number<span style='color:rgba(255,255,255,1)'>,</span> String<span style='color:rgba(255,255,255,1)'>,</span> Boolean<span style='color:rgba(255,255,255,1)'>,</span> Array<span style='color:rgba(255,255,255,1)'>,</span> Object<span style='color:rgba(255,255,255,1)'>,
<span class='span_code_line'></span>}</span></pre>
</div>
<p>The return value of the custom function is unified with <span class='mark'>STJson</span>, because <span class='mark'>STJson</span> can interface perfectly with <span class='mark'>STJsonPath</span>, where <span class='mark'>STJsonPath</span> can operate directly on the return value of the custom function using <span class='mark'>selector</span>. For example, the following example adds a <span class='mark'>matches</span> function to <span class='mark'>STJsonPath</span> for regular expression manipulation.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>STJsonPath</span><span style='color:rgba(112,128,144,1)'>.CustomFunctions</span><span style='color:rgba(219,112,147,1)'>.Add</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"matches"</span><span style='color:rgba(255,255,255,1)'>, (</span>objs<span style='color:rgba(255,255,255,1)'>)</span> <span style='color:rgba(255,255,255,1)'>=></span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(100,149,237,1)'>var</span> json_ret <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(255,255,255,1)'>();</span>
<span class='span_code_line'></span>    json_ret<span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>    json_ret<span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"values"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.CreateArray</span><span style='color:rgba(255,255,255,1)'>());</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>if</span> <span style='color:rgba(255,255,255,1)'>(</span>objs<span style='color:rgba(112,128,144,1)'>.Length</span> <span style='color:rgba(255,255,255,1)'>!=</span> <span style='color:rgba(144,238,144,1)'>2</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>return</span> json_ret<span style='color:rgba(255,255,255,1)'>;
<span class='span_code_line'></span>    }</span>
<span class='span_code_line'></span>    <span style='color:rgba(100,149,237,1)'>var</span> ms <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>Regex</span><span style='color:rgba(219,112,147,1)'>.Matches</span><span style='color:rgba(255,255,255,1)'>(</span>objs<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>]</span><span style='color:rgba(112,128,144,1)'>.Value</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(),</span> objs<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>]</span><span style='color:rgba(112,128,144,1)'>.Value</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>());</span>
<span class='span_code_line'></span>    json_ret<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>]</span><span style='color:rgba(219,112,147,1)'>.SetValue</span><span style='color:rgba(255,255,255,1)'>(</span>ms<span style='color:rgba(112,128,144,1)'>.Count</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>foreach</span> <span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>Match</span> v <span style='color:rgba(30,144,255,1)'>in</span> ms<span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>        json_ret<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(255,165,0,1)'>"values"</span><span style='color:rgba(255,255,255,1)'>]</span><span style='color:rgba(219,112,147,1)'>.Append</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.FromObject</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>            success <span style='color:rgba(255,255,255,1)'>=</span> v<span style='color:rgba(112,128,144,1)'>.Success</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            index <span style='color:rgba(255,255,255,1)'>=</span> v<span style='color:rgba(112,128,144,1)'>.Index</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            length <span style='color:rgba(255,255,255,1)'>=</span> v<span style='color:rgba(112,128,144,1)'>.Length</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(30,144,255,1)'>value</span> <span style='color:rgba(255,255,255,1)'>=</span> v<span style='color:rgba(112,128,144,1)'>.Value</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}));
<span class='span_code_line'></span>    }</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>return</span> json_ret<span style='color:rgba(255,255,255,1)'>;
<span class='span_code_line'></span>});</span></pre>
</div>
<p>Then we need to filter out the elements of <span class='mark'>hobby</span> that contain two <span class='mark'>a</span>s or <span class='mark'>o</span>s:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"*.hobby.*[?(matches(@,'a|o').count == 2)]"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>    <span style='color:rgba(0,255,255,1)'>"cooking"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"basketball"</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>]</span></pre>
</div>
<div class='div_hightlight' style='background-color:pink;color:black'>
<p>The <span class='mark'>custom function</span> takes precedence over the <span class='mark'>built-in function</span>, that is, if there is a function with the same name in the <span class='mark'>custom function</span> and the <span class='mark'>built-in function</span>, the <span class='mark'>custom function</span> is called first.</p>
</div>
<div><h2 class='h_option anchor_point' name='b_g'>Selectors in expressions</h2></div>
<p>A selector in an expression returns only the first result selected, not a list of arrays.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>]</span><span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>STJsonPath</span><span style='color:rgba(219,112,147,1)'>.TestExpression</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>],</span> json_src<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>],</span> <span style='color:rgba(255,165,0,1)'>"@.name"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"Tom"</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"expression"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"parsed"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"{[@]['name']}"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"polish"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"[@]['name']"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>],</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"steps"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>
<span class='span_code_line'></span>    ],</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"check_result"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"parsed"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"[@]['name']"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"selector"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"root_json"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"{\"name\":\"Tom\",\"age\":16,\"gender\":0,\"hobby\":[\"cooking\",\"sing\"]}"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"current_json"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"{\"name\":\"Tom\",\"age\":16,\"gender\":0,\"hobby\":[\"cooking\",\"sing\"]}"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"selected_json"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"[\"Tom\"]"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"result"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>                     <span style='color:rgba(0,255,0,1)'>// The return value will get only the first result.</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"String"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"text"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tom"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>    },</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"return"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"bool"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"value_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"String"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"text"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tom"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>}</span></pre>
</div>
<div><h2 class='h_option anchor_point' name='b_h'>Select mode</h2></div>
<p>Normal mode (default):</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"..name"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(0,255,255,1)'>STJsonPathSelectMode</span><span style='color:rgba(112,128,144,1)'>.ItemOnly</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>    <span style='color:rgba(0,255,255,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"Tony"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"Andy"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"Kun"</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>]</span></pre>
</div>
<p>Path mode：</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"..name"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(0,255,255,1)'>STJsonPathSelectMode</span><span style='color:rgba(112,128,144,1)'>.ItemWithPath</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>    {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"path"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"name"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>],</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"item"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tom"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"path"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"name"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>],</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"item"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tony"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"path"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(144,238,144,1)'>2</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"name"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>],</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"item"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Andy"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"path"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(144,238,144,1)'>3</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"name"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>],</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"item"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Kun"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>]</span></pre>
</div>
<p>Structure mode：</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"..name"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(0,255,255,1)'>STJsonPathSelectMode</span><span style='color:rgba(112,128,144,1)'>.KeepStructure</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>    {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tom"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tony"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Andy"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Kun"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>]</span></pre>
</div>
<div><h2 class='h_option anchor_point' name='b_i'>ParsedTokens</h2></div>
<p><span class='mark'>GetParsedTokens()</span> is used to get how the current <span class='mark'>STJsonPath</span> string is parsed internally and output as <span class='mark'>STJson</span>. If you want to write a parser too, it might give you some ideas.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJsonPath</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"$..[?(matches(@.name,'u').count == 1)]"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.GetParsedTokens</span><span style='color:rgba(255,255,255,1)'>()</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>2</span><span style='color:rgba(255,255,255,1)'>)
<span class='span_code_line'></span>    );</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>  <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"entry"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>  <span style='color:rgba(255,165,0,1)'>"parsed"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"[..]{matches({[@]['name']}, {'u'}) == 1}"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>  <span style='color:rgba(255,165,0,1)'>"items"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>    {</span>
<span class='span_code_line'></span>      <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"selector_item"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>      <span style='color:rgba(255,165,0,1)'>"item_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Depth"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>      <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>".."</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>      <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"expression"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>      <span style='color:rgba(255,165,0,1)'>"parsed"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"{matches({[@]['name']}, {'u'}) == 1}"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>      <span style='color:rgba(255,165,0,1)'>"items"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>        {</span>
<span class='span_code_line'></span>          <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"function"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>          <span style='color:rgba(255,165,0,1)'>"parsed"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"matches({[@]['name']}, {'u'})"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>          <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"matches"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>          <span style='color:rgba(255,165,0,1)'>"args"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"parsed"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"({[@]['name']}, {'u'})"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"items"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>              {</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"expression"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"parsed"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"{[@]['name']}"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"items"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>                  {</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"expression_item"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"item_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"selector"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"items"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>                      {</span>
<span class='span_code_line'></span>                        <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"selector_item"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                        <span style='color:rgba(255,165,0,1)'>"item_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Current"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                        <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"@"</span>
<span class='span_code_line'></span>                      <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>                        <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"selector_item"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                        <span style='color:rgba(255,165,0,1)'>"item_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"List"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                        <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>                          <span style='color:rgba(255,165,0,1)'>"name"</span>
<span class='span_code_line'></span>                        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>                      }
<span class='span_code_line'></span>                    ]
<span class='span_code_line'></span>                  }
<span class='span_code_line'></span>                ]
<span class='span_code_line'></span>              }, {</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"expression"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"parsed"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"{'u'}"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"items"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>                  {</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"expression_item"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"item_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"string"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"u"</span>
<span class='span_code_line'></span>                  <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>                ]
<span class='span_code_line'></span>              }
<span class='span_code_line'></span>            ]
<span class='span_code_line'></span>          },</span>
<span class='span_code_line'></span>          <span style='color:rgba(255,165,0,1)'>"selector"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"parsed"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"['count']"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"items"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>              {</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"selector_item"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"item_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"List"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>                  <span style='color:rgba(255,165,0,1)'>"count"</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>              }
<span class='span_code_line'></span>            ]
<span class='span_code_line'></span>          }
<span class='span_code_line'></span>        }, {</span>
<span class='span_code_line'></span>          <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"expression_item"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>          <span style='color:rgba(255,165,0,1)'>"item_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"long"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>          <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>          <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"expression_item"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>          <span style='color:rgba(255,165,0,1)'>"item_type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"operator"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>          <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"=="</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>      ]
<span class='span_code_line'></span>    }
<span class='span_code_line'></span>  ]
<span class='span_code_line'></span>}</span></pre>
</div>
<h1 class='h_title anchor_point' name='b_j'>STJson [Advanced]</h1>
<div><h2 class='h_option anchor_point' name='b_k'>Get value</h2></div>
<p>Imagine a scenario where, as a <span class='mark'>WEB</span> back-end service, we need to process <span class='mark'>Json</span> data submitted by the front-end, assuming we expect the following <span class='mark'>Json</span> data:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span>{
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"type"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"get_list"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"page"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"from"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>100</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"size"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>10</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>},</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"other"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{}
<span class='span_code_line'></span>}</span></pre>
</div>
<p>And we have converted the above data into <span class='mark'>STJson</span> and named it <span class='mark'>json_post</span>. Where <span class='mark'>from</span> and <span class='mark'>size</span> are used for page-flipping function. Then the backend may make the following judgments:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>if</span><span style='color:rgba(255,255,255,1)'>(</span>json_post<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(255,165,0,1)'>"page"</span><span style='color:rgba(255,255,255,1)'>]</span> <span style='color:rgba(255,255,255,1)'>==</span> <span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>) {</span> <span style='color:rgba(0,255,0,1)'>/* do something */</span> <span style='color:rgba(255,255,255,1)'>}</span>
<span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>if</span><span style='color:rgba(255,255,255,1)'>(</span>json_post<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(255,165,0,1)'>"page"</span><span style='color:rgba(255,255,255,1)'>][</span><span style='color:rgba(255,165,0,1)'>"from"</span><span style='color:rgba(255,255,255,1)'>]</span> <span style='color:rgba(255,255,255,1)'>==</span> <span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>) {</span> <span style='color:rgba(0,255,0,1)'>/* do something */</span> <span style='color:rgba(255,255,255,1)'>}</span>
<span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>if</span><span style='color:rgba(255,255,255,1)'>(</span>json_post<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(255,165,0,1)'>"page"</span><span style='color:rgba(255,255,255,1)'>][</span><span style='color:rgba(255,165,0,1)'>"from"</span><span style='color:rgba(255,255,255,1)'>]</span><span style='color:rgba(112,128,144,1)'>.ValueType</span> <span style='color:rgba(255,255,255,1)'>!=</span> <span style='color:rgba(0,255,255,1)'>STJsonValueType</span><span style='color:rgba(112,128,144,1)'>.Long</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>    <span style='color:rgba(0,255,0,1)'>/* do something */</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>}</span>
<span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>int</span> nFrom <span style='color:rgba(255,255,255,1)'>=</span> json_post<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(255,165,0,1)'>"page"</span><span style='color:rgba(255,255,255,1)'>][</span><span style='color:rgba(255,165,0,1)'>"from"</span><span style='color:rgba(255,255,255,1)'>]</span><span style='color:rgba(219,112,147,1)'>.GetValue</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(100,149,237,1)'>int</span>><span style='color:rgba(255,255,255,1)'>();</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>// Or just be rude.</span>
<span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>int</span> nFrom <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>try</span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    nFrom <span style='color:rgba(255,255,255,1)'>=</span> json_post<span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(255,165,0,1)'>"page"</span><span style='color:rgba(255,255,255,1)'>][</span><span style='color:rgba(255,165,0,1)'>"from"</span><span style='color:rgba(255,255,255,1)'>]</span><span style='color:rgba(219,112,147,1)'>.GetValue</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(100,149,237,1)'>int</span>><span style='color:rgba(255,255,255,1)'>();
<span class='span_code_line'></span>}</span><span style='color:rgba(30,144,255,1)'>catch</span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(0,255,0,1)'>/* do something */</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>}</span></pre>
</div>
<p>Obviously the above code is driving you crazy. Of course, you can create an entity object for it in the backend code to reduce the hassle, and then bind <span class='mark'>Json</span> to the entity object. But creating an entity object for each <span class='mark'>Post</span> data type is also quite annoying. But if you use the following code.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>int</span> nFrom <span style='color:rgba(255,255,255,1)'>=</span> json_post<span style='color:rgba(219,112,147,1)'>.GetValue</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(100,149,237,1)'>int</span>><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"page.from"</span><span style='color:rgba(255,255,255,1)'>);</span></pre>
</div>
<p>Maybe you are wondering, what if the path does not exist or <span class='mark'>from</span> is not a number at all?emm.... The above code will still report an error, because the internal call to the above code is:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>public static</span> <span style='color:rgba(0,255,255,1)'>T</span> <span style='color:rgba(255,0,255,1)'>GetValue</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(0,255,255,1)'>T</span>><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(30,144,255,1)'>this</span> STJson <span style='color:rgba(0,255,255,1)'>json</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(100,149,237,1)'>string</span> strJsonPath<span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>return</span> json<span style='color:rgba(219,112,147,1)'>.GetValue</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(0,255,255,1)'>T</span>><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJsonPath</span><span style='color:rgba(255,255,255,1)'>(</span>strJsonPath<span style='color:rgba(255,255,255,1)'>));
<span class='span_code_line'></span>}</span>
<span class='span_code_line'></span>
<span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>public static</span> <span style='color:rgba(0,255,255,1)'>T</span> <span style='color:rgba(255,0,255,1)'>GetValue</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(0,255,255,1)'>T</span>><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(30,144,255,1)'>this</span> STJson <span style='color:rgba(0,255,255,1)'>json</span><span style='color:rgba(255,255,255,1)'>,</span> STJsonPath jsonPath<span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>    <span style='color:rgba(100,149,237,1)'>var</span> j <span style='color:rgba(255,255,255,1)'>=</span> jsonPath<span style='color:rgba(219,112,147,1)'>.SelectFirst</span><span style='color:rgba(255,255,255,1)'>(</span>json<span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>if</span> <span style='color:rgba(255,255,255,1)'>(</span>j <span style='color:rgba(255,255,255,1)'>==</span> <span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>throw new</span> <span style='color:rgba(0,255,255,1)'>STJsonPathException</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"Can not selected a object with path {"</span> <span style='color:rgba(255,255,255,1)'>+</span> jsonPath<span style='color:rgba(112,128,144,1)'>.SourceText</span> <span style='color:rgba(255,255,255,1)'>+</span> <span style='color:rgba(255,165,0,1)'>"}"</span><span style='color:rgba(255,255,255,1)'>);
<span class='span_code_line'></span>    }</span>
<span class='span_code_line'></span>    <span style='color:rgba(100,149,237,1)'>var</span> t <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(100,149,237,1)'>typeof</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>T</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>    <span style='color:rgba(100,149,237,1)'>bool</span> bProcessed <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>    <span style='color:rgba(100,149,237,1)'>var</span> convert <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>STJsonBuildInConverter</span><span style='color:rgba(219,112,147,1)'>.Get</span><span style='color:rgba(255,255,255,1)'>(</span>t<span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>if</span> <span style='color:rgba(255,255,255,1)'>(</span>convert <span style='color:rgba(255,255,255,1)'>!=</span> <span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>        <span style='color:rgba(100,149,237,1)'>var</span> value <span style='color:rgba(255,255,255,1)'>=</span> convert<span style='color:rgba(219,112,147,1)'>.JsonToObject</span><span style='color:rgba(255,255,255,1)'>(</span>t<span style='color:rgba(255,255,255,1)'>,</span> json<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>ref</span> bProcessed<span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>if</span> <span style='color:rgba(255,255,255,1)'>(</span>bProcessed<span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>            <span style='color:rgba(30,144,255,1)'>return</span> <span style='color:rgba(255,255,255,1)'>(</span>T<span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(30,144,255,1)'>value</span><span style='color:rgba(255,255,255,1)'>;
<span class='span_code_line'></span>        }
<span class='span_code_line'></span>    }</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>return</span> <span style='color:rgba(255,255,255,1)'>(</span>T<span style='color:rgba(255,255,255,1)'>)</span>j<span style='color:rgba(112,128,144,1)'>.Value</span><span style='color:rgba(255,255,255,1)'>;
<span class='span_code_line'></span>}</span></pre>
</div>
<p>Because when there is no element, do not know what value needs to be returned, the reader may think that it is impossible to get the value, return a default value is good, indeed, can be so designed, but the caller how to determine the value returned is the real value or the default value. There is no way to determine if it is an exception. Unless a default value is forced to be specified.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>int</span> nFrom <span style='color:rgba(255,255,255,1)'>=</span> json_post<span style='color:rgba(219,112,147,1)'>.GetValue</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(100,149,237,1)'>int</span>><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"page.from"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>);</span></pre>
</div>
<p>Returns the element value if the element exists and can be converted properly, otherwise returns <span class='mark'>0</span>.</p>
<p>Or to know if the real value is returned:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>int</span> nFrom <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> bFlag <span style='color:rgba(255,255,255,1)'>=</span> json_src<span style='color:rgba(219,112,147,1)'>.GetValue</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(100,149,237,1)'>int</span>><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"page.from"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>out</span> nFrom<span style='color:rgba(255,255,255,1)'>);</span></pre>
</div>
<div class='div_hightlight' style='background-color:goldenrod;color:black'>
<p>If the filled <span class='mark'>strJsonPath</span> will get more than one value, the first value is taken.</p>
</div>
<div><h2 class='h_option anchor_point' name='b_l'>Set value</h2></div>
<p>If we need to construct a <span class='mark'>Json</span> manually we can add elements via <span class='mark'>STJson.SetItem()</span>. However, some scenarios seem a bit tricky to use this way, for example, take the <span class='mark'>query</span> syntax of the <span class='mark'>ElasticSearch</span> database as an example. We need to construct a data as follows:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span>{
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"query"</span><span style='color:rgba(255,255,255,1)'>:</span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"term"</span><span style='color:rgba(255,255,255,1)'>:</span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"field_name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"field_value"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>    }
<span class='span_code_line'></span>}</span></pre>
</div>
<p>Then we need to construct an <span class='mark'>STJson</span> object as in the previous case like this:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> json <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(255,255,255,1)'>()</span>
<span class='span_code_line'></span>    <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"query"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(255,255,255,1)'>()</span>
<span class='span_code_line'></span>        <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"term"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(255,255,255,1)'>()</span>
<span class='span_code_line'></span>            <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"field_name"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"field_value"</span><span style='color:rgba(255,255,255,1)'>))
<span class='span_code_line'></span>        );</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>// or</span>
<span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> json <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.FromObject</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    query <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>        term <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>            field_name <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(255,165,0,1)'>"field_value"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>    }
<span class='span_code_line'></span>});</span></pre>
</div>
<p>But it is also possible to write the code like this:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> json <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(255,255,255,1)'>()</span><span style='color:rgba(219,112,147,1)'>.Set</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"query.term.field_name"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"field_value"</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json<span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"query"</span><span style='color:rgba(255,255,255,1)'>:</span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"term"</span><span style='color:rgba(255,255,255,1)'>:</span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"field_name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"field_value"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>    }
<span class='span_code_line'></span>}</span></pre>
</div>
<p>Or even this:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> json <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(255,255,255,1)'>()</span><span style='color:rgba(219,112,147,1)'>.Set</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"array[0:4].[key_1,key_2]"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json<span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"array"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>        {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"key_1"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"key_2"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"value"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"key_1"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"key_2"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"value"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"key_1"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"key_2"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"value"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"key_1"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"key_2"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"value"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"key_1"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"key_2"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"value"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>    ]
<span class='span_code_line'></span>}</span></pre>
</div>
<div class='div_hightlight' style='background-color:pink;color:black'>
<p>Only <span class='mark'>list selector</span> and <span class='mark'>slice selector</span> are supported in <span class='mark'>Set</span>. No other selectors are supported.</p>
</div>
<div><h2 class='h_option anchor_point' name='b_m'>Callback</h2></div>
<p>With the <span class='mark'>Set</span> above are we able to add a <span class='mark'>coding</span> to each of the hobbies in <span class='mark'>json_src</span>? It doesn't seem possible. After all, adding data to <span class='mark'>hobby</span> requires <span class='mark'>append</span> not <span class='mark'>set</span>.</p>
<p>Of course there is not no way around it.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span>json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"*.hobby"</span><span style='color:rgba(255,255,255,1)'>, (</span>p<span style='color:rgba(255,255,255,1)'>,</span> j<span style='color:rgba(255,255,255,1)'>)</span> <span style='color:rgba(255,255,255,1)'>=></span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    j<span style='color:rgba(219,112,147,1)'>.Append</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"coding"</span><span style='color:rgba(255,255,255,1)'>);
<span class='span_code_line'></span>});</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>    {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>16</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"cooking"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"sing"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"coding"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    },</span>
<span class='span_code_line'></span>    ...
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>]</span></pre>
</div>
<p>Two kinds of callback functions are supported in <span class='mark'>Select</span>, one requires a return value and the other does not, as in the above. And the following one with return value.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> json <span style='color:rgba(255,255,255,1)'>=</span> json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"*.hobby.*"</span><span style='color:rgba(255,255,255,1)'>, (</span>p<span style='color:rgba(255,255,255,1)'>,</span> j<span style='color:rgba(255,255,255,1)'>)</span> <span style='color:rgba(255,255,255,1)'>=></span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>return new</span> <span style='color:rgba(0,255,255,1)'>STJsonPathCallBackResult</span><span style='color:rgba(255,255,255,1)'>() {</span>
<span class='span_code_line'></span>        Selected <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>,</span>            <span style='color:rgba(0,255,0,1)'>// If or not to add this json to the result.</span>
<span class='span_code_line'></span>        Json <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(255,255,255,1)'>()</span>         <span style='color:rgba(0,255,0,1)'>// The json that needs to be added to the result.</span>
<span class='span_code_line'></span>            <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"path"</span><span style='color:rgba(255,255,255,1)'>,</span> p<span style='color:rgba(255,255,255,1)'>)</span>
<span class='span_code_line'></span>            <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"item"</span><span style='color:rgba(255,255,255,1)'>,</span> j<span style='color:rgba(112,128,144,1)'>.Value</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>()</span><span style='color:rgba(219,112,147,1)'>.ToUpper</span><span style='color:rgba(255,255,255,1)'>())
<span class='span_code_line'></span>    };
<span class='span_code_line'></span>});</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json<span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>    {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"path"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>0</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>],</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"item"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"COOKING"</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>},</span>
<span class='span_code_line'></span>    ...
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>]</span></pre>
</div>
<div><h2 class='h_option anchor_point' name='b_n'>PathItem</h2></div>
<p>There is a rather special data structure in <span class='mark'>STJsonPath</span>.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span>[
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"path"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            ...
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>],</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"item"</span><span style='color:rgba(255,255,255,1)'>:</span> ...
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>},</span>
<span class='span_code_line'></span>    ...
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>]</span></pre>
</div>
<p>Its structure can be restored by <span class='mark'>RestorePathJson()</span>.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> json <span style='color:rgba(255,255,255,1)'>=</span> json_src<span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"*.hobby.*"</span><span style='color:rgba(255,255,255,1)'>, (</span>p<span style='color:rgba(255,255,255,1)'>,</span> j<span style='color:rgba(255,255,255,1)'>)</span> <span style='color:rgba(255,255,255,1)'>=></span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>return new</span> <span style='color:rgba(0,255,255,1)'>STJsonPathCallBackResult</span><span style='color:rgba(255,255,255,1)'>() {</span>
<span class='span_code_line'></span>        Selected <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        Json <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(255,255,255,1)'>()</span>
<span class='span_code_line'></span>            <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"path"</span><span style='color:rgba(255,255,255,1)'>,</span> p<span style='color:rgba(255,255,255,1)'>)</span>
<span class='span_code_line'></span>            <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"item"</span><span style='color:rgba(255,255,255,1)'>,</span> j<span style='color:rgba(112,128,144,1)'>.Value</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>()</span><span style='color:rgba(219,112,147,1)'>.ToUpper</span><span style='color:rgba(255,255,255,1)'>())
<span class='span_code_line'></span>    };
<span class='span_code_line'></span>});</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(0,255,255,1)'>STJsonPath</span><span style='color:rgba(219,112,147,1)'>.RestorePathJson</span><span style='color:rgba(255,255,255,1)'>(</span>json<span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>    {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"COOKING"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"SING"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }, {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"GAME"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"DANCE"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }, {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"DRAW"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"SING"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }, {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"SING"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"DANCE"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"RAP"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"BASKETBALL"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }
<span class='span_code_line'></span>]</span></pre>
</div>
<div><h2 class='h_option anchor_point' name='b_o'>Clone</h2></div>
<p>If you want to add <span class='mark'>coding</span> to all user hobbies. but don't want to affect the source data, then you can clone a copy of the data for the operation.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span>json_src<span style='color:rgba(219,112,147,1)'>.Clone</span><span style='color:rgba(255,255,255,1)'>()</span><span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"*.hobby"</span><span style='color:rgba(255,255,255,1)'>, (</span>p<span style='color:rgba(255,255,255,1)'>,</span> j<span style='color:rgba(255,255,255,1)'>)</span> <span style='color:rgba(255,255,255,1)'>=></span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    j<span style='color:rgba(219,112,147,1)'>.Append</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"coding"</span><span style='color:rgba(255,255,255,1)'>);
<span class='span_code_line'></span>});</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>    {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>16</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"cooking"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"sing"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    },</span>
<span class='span_code_line'></span>    ...
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>]</span></pre>
</div>
<h1 class='h_title anchor_point' name='b_p'>Aggregation</h1>
<p>There are some extensions built into <span class='mark'>STJson</span> for aggregate operations and simple data processing. Combined with <span class='mark'>STJsonPath</span>, you can do some data manipulation quickly and easily.</p>
<div><h2 class='h_option anchor_point' name='b_q'>sort</h2></div>
<p><span class='mark'>Sort()</span> is used to sort the data, internally in a <span class='mark'>Merge Sort</span> manner. This function has the following formal signature:</p>
<div class='div_table'>
<table>
<tr><th>return</th><th>signature</th><th>note</th></tr>
<tr><td>STJson</td><td>Sort()</td><td>Sort without specifying <span class='mark'>path</span>. Default is ascending.</td></tr>
<tr class='tr_hight'><td>STJson</td><td>Sort(bool)</td><td>Sort without specifying <span class='mark'>path</span>, specifying whether to sort in descending order.</td></tr>
<tr><td>STJson</td><td>Sort(params object[])</td><td>Sort without specifying <span class='mark'>path</span> or whether to sort in descending order.</td></tr>
</table>
</div>
<p>Sorting without specifying <span class='mark'>path</span>:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> arr_obj <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(100,149,237,1)'>object</span><span style='color:rgba(255,255,255,1)'>[] {</span> <span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>2</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>5</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>6</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(255,255,255,1)'>{</span> aa <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(255,165,0,1)'>"aa"</span> <span style='color:rgba(255,255,255,1)'>} };</span>
<span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> json_objs <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.FromObject</span><span style='color:rgba(255,255,255,1)'>(</span>arr_obj<span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_objs<span style='color:rgba(219,112,147,1)'>.Sort</span><span style='color:rgba(255,255,255,1)'>());</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_objs<span style='color:rgba(219,112,147,1)'>.Sort</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(0,255,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(144,238,144,1)'>2</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(144,238,144,1)'>5</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(144,238,144,1)'>6</span><span style='color:rgba(255,255,255,1)'>,{</span><span style='color:rgba(255,165,0,1)'>"aa"</span><span style='color:rgba(255,255,255,1)'>:</span><span style='color:rgba(255,165,0,1)'>"aa"</span><span style='color:rgba(255,255,255,1)'>},</span><span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>[</span><span style='color:rgba(144,238,144,1)'>6</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(144,238,144,1)'>5</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(144,238,144,1)'>2</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,{</span><span style='color:rgba(255,165,0,1)'>"aa"</span><span style='color:rgba(255,255,255,1)'>:</span><span style='color:rgba(255,165,0,1)'>"aa"</span><span style='color:rgba(255,255,255,1)'>},</span><span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>]</span></pre>
</div>
<p>Are you wondering why the result is the way it is? But before that why don't you wonder why you need to use such an array to sort?</p>
<p>Inside <span class='mark'>Sort</span>, a number is obtained for each element and the index of the element is recorded, then the number is sorted and finally an array is reassembled according to the index position to achieve the sorting purpose. The rules for how to get the number of an element are as follows:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>switch</span> <span style='color:rgba(255,255,255,1)'>(</span>item<span style='color:rgba(112,128,144,1)'>.ValueType</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>case</span> <span style='color:rgba(0,255,255,1)'>STJsonValueType</span><span style='color:rgba(112,128,144,1)'>.Long</span><span style='color:rgba(255,255,255,1)'>:</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>case</span> <span style='color:rgba(0,255,255,1)'>STJsonValueType</span><span style='color:rgba(112,128,144,1)'>.Double</span><span style='color:rgba(255,255,255,1)'>:</span>
<span class='span_code_line'></span>        d_temp <span style='color:rgba(255,255,255,1)'>=</span> item<span style='color:rgba(219,112,147,1)'>.GetValue</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(100,149,237,1)'>double</span>><span style='color:rgba(255,255,255,1)'>();</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>break</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>case</span> <span style='color:rgba(0,255,255,1)'>STJsonValueType</span><span style='color:rgba(112,128,144,1)'>.Boolean</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(0,255,0,1)'>// true will convert to 1</span>
<span class='span_code_line'></span>        d_temp <span style='color:rgba(255,255,255,1)'>=</span> item<span style='color:rgba(219,112,147,1)'>.GetValue</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(100,149,237,1)'>bool</span>><span style='color:rgba(255,255,255,1)'>()</span> <span style='color:rgba(255,255,255,1)'>?</span> <span style='color:rgba(144,238,144,1)'>1</span> <span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>break</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>case</span> <span style='color:rgba(0,255,255,1)'>STJsonValueType</span><span style='color:rgba(112,128,144,1)'>.Datetime</span><span style='color:rgba(255,255,255,1)'>:</span>
<span class='span_code_line'></span>        d_temp <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>Convert</span><span style='color:rgba(219,112,147,1)'>.ToDouble</span><span style='color:rgba(255,255,255,1)'>(</span>item<span style='color:rgba(219,112,147,1)'>.GetValue</span><span style='color:rgba(255,255,255,1)'><</span><span style='color:rgba(0,255,255,1)'>DateTime</span>><span style='color:rgba(255,255,255,1)'>());</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>break</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>case</span> <span style='color:rgba(0,255,255,1)'>STJsonValueType</span><span style='color:rgba(112,128,144,1)'>.String</span><span style='color:rgba(255,255,255,1)'>:</span>
<span class='span_code_line'></span>        d_temp <span style='color:rgba(255,255,255,1)'>=</span> item<span style='color:rgba(112,128,144,1)'>.Value</span> <span style='color:rgba(255,255,255,1)'>==</span> <span style='color:rgba(30,144,255,1)'>null</span> <span style='color:rgba(255,255,255,1)'>?</span> <span style='color:rgba(144,238,144,1)'>0</span> <span style='color:rgba(255,255,255,1)'>:</span> item<span style='color:rgba(112,128,144,1)'>.Value</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>()</span><span style='color:rgba(112,128,144,1)'>.Length</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>break</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>default</span><span style='color:rgba(255,255,255,1)'>:</span>    <span style='color:rgba(0,255,0,1)'>// For other types just let them always be at the end.</span>
<span class='span_code_line'></span>        d_temp <span style='color:rgba(255,255,255,1)'>=</span> arr_b_desc<span style='color:rgba(255,255,255,1)'>[</span>j<span style='color:rgba(255,255,255,1)'>]</span> <span style='color:rgba(255,255,255,1)'>?</span> <span style='color:rgba(100,149,237,1)'>double</span><span style='color:rgba(112,128,144,1)'>.MinValue</span> <span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(100,149,237,1)'>double</span><span style='color:rgba(112,128,144,1)'>.MaxValue</span><span style='color:rgba(255,255,255,1)'>;</span>
<span class='span_code_line'></span>        <span style='color:rgba(30,144,255,1)'>break</span><span style='color:rgba(255,255,255,1)'>;
<span class='span_code_line'></span>}</span></pre>
</div>
<p>So if you don't have that weird array then everything will be fine. What if I really want to sort only the numbers inside?</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> arr_obj <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(100,149,237,1)'>object</span><span style='color:rgba(255,255,255,1)'>[] {</span> <span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>2</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>5</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>6</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>null</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(255,255,255,1)'>{</span> aa <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(255,165,0,1)'>"aa"</span> <span style='color:rgba(255,255,255,1)'>} };</span>
<span class='span_code_line'></span><span style='color:rgba(100,149,237,1)'>var</span> json_objs <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.FromObject</span><span style='color:rgba(255,255,255,1)'>(</span>arr_obj<span style='color:rgba(255,255,255,1)'>)</span>
<span class='span_code_line'></span>    <span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"..[?(typeof(@) in ['long', 'double'])]"</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_objs<span style='color:rgba(219,112,147,1)'>.Sort</span><span style='color:rgba(255,255,255,1)'>());</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_objs<span style='color:rgba(219,112,147,1)'>.Sort</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span><span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(144,238,144,1)'>2</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(144,238,144,1)'>5</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(144,238,144,1)'>6</span><span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>[</span><span style='color:rgba(144,238,144,1)'>6</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(144,238,144,1)'>5</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(144,238,144,1)'>2</span><span style='color:rgba(255,255,255,1)'>,</span><span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>]</span></pre>
</div>
<p>Specify <span class='mark'>path</span> for sorting:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Sort</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>    {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tony"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>16</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"game"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"dance"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }, {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>16</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"cooking"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"sing"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }, {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Andy"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>20</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"draw"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"sing"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }, {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Kun"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>26</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"sing"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"dance"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"rap"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"basketball"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }
<span class='span_code_line'></span>]</span></pre>
</div>
<p>Of course you can also specify a descending order:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Sort</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span></pre>
</div>
<p>Multiple fields can also be specified for sorting at the same time:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Sort</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>false</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>    {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tony"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>16</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"game"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"dance"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }, {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>16</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"cooking"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"sing"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }, {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Kun"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>26</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"sing"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"dance"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"rap"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"basketball"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }, {</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Andy"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>20</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"draw"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"sing"</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>    }
<span class='span_code_line'></span>]</span></pre>
</div>
<p>The above is to use <span class='mark'>gender</span> for ascending order, and then for the same value and then <span class='mark'>age</span> for descending order. The <span class='mark'>Sort</span> function parameter rules are as follows:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(255,0,255,1)'>Sort</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(100,149,237,1)'>string</span> strJsonPath<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(100,149,237,1)'>bool</span> isDesc<span style='color:rgba(255,255,255,1)'>[,</span> <span style='color:rgba(100,149,237,1)'>string</span> strJsonPath<span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(100,149,237,1)'>bool</span> isDesc<span style='color:rgba(255,255,255,1)'>]</span><span style='color:rgba(255,255,255,1)'>*</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>// STLib.Json.STJsonExtension.cs:Sort()</span>
<span class='span_code_line'></span><span style='color:rgba(30,144,255,1)'>public static</span> <span style='color:rgba(0,255,255,1)'>STJson</span> <span style='color:rgba(255,0,255,1)'>Sort</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(30,144,255,1)'>this</span> STJson <span style='color:rgba(0,255,255,1)'>json</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(100,149,237,1)'>params object</span><span style='color:rgba(255,255,255,1)'>[]</span> fields<span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>    <span style='color:rgba(100,149,237,1)'>var</span> jsonSort <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(219,112,147,1)'>.CreateArray</span><span style='color:rgba(255,255,255,1)'>();</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>for</span> <span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(100,149,237,1)'>int</span> i <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>;</span> i <span style='color:rgba(255,255,255,1)'><</span> fields<span style='color:rgba(112,128,144,1)'>.Length</span><span style='color:rgba(255,255,255,1)'>;</span> i <span style='color:rgba(255,255,255,1)'>+=</span> <span style='color:rgba(144,238,144,1)'>2</span><span style='color:rgba(255,255,255,1)'>) {</span>
<span class='span_code_line'></span>        <span style='color:rgba(100,149,237,1)'>var</span> j <span style='color:rgba(255,255,255,1)'>=</span> <span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJson</span><span style='color:rgba(255,255,255,1)'>()</span>
<span class='span_code_line'></span>            <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"path"</span><span style='color:rgba(255,255,255,1)'>,</span> fields<span style='color:rgba(255,255,255,1)'>[</span>i<span style='color:rgba(255,255,255,1)'>]</span> <span style='color:rgba(255,255,255,1)'>==</span> <span style='color:rgba(30,144,255,1)'>null</span> <span style='color:rgba(255,255,255,1)'>?</span> <span style='color:rgba(30,144,255,1)'>null</span> <span style='color:rgba(255,255,255,1)'>:</span> fields<span style='color:rgba(255,255,255,1)'>[</span>i<span style='color:rgba(255,255,255,1)'>]</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>())</span>
<span class='span_code_line'></span>            <span style='color:rgba(219,112,147,1)'>.SetItem</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"desc"</span><span style='color:rgba(255,255,255,1)'>,</span> i <span style='color:rgba(255,255,255,1)'>+</span> <span style='color:rgba(144,238,144,1)'>1</span> <span style='color:rgba(255,255,255,1)'><</span> fields<span style='color:rgba(112,128,144,1)'>.Length</span> <span style='color:rgba(255,255,255,1)'>?</span> <span style='color:rgba(0,255,255,1)'>Convert</span><span style='color:rgba(219,112,147,1)'>.ToBoolean</span><span style='color:rgba(255,255,255,1)'>(</span>fields<span style='color:rgba(255,255,255,1)'>[</span>i <span style='color:rgba(255,255,255,1)'>+</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>])</span> <span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(30,144,255,1)'>false</span><span style='color:rgba(255,255,255,1)'>);</span>
<span class='span_code_line'></span>        jsonSort<span style='color:rgba(219,112,147,1)'>.Append</span><span style='color:rgba(255,255,255,1)'>(</span>j<span style='color:rgba(255,255,255,1)'>);
<span class='span_code_line'></span>    }</span>
<span class='span_code_line'></span>    <span style='color:rgba(30,144,255,1)'>return</span> json<span style='color:rgba(219,112,147,1)'>.Sort</span><span style='color:rgba(255,255,255,1)'>(</span>jsonSort<span style='color:rgba(255,255,255,1)'>);</span> <span style='color:rgba(0,255,0,1)'>// internal</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>}</span></pre>
</div>
<div><h2 class='h_option anchor_point' name='b_r'>group</h2></div>
<p><span class='mark'>Group()</span> is used to group the data by specifying <span class='mark'>path</span>. It is used in the following way:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Group</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>        {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"items"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>                {</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>16</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>                        <span style='color:rgba(255,165,0,1)'>"cooking"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"sing"</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>                }, {</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tony"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>16</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>                        <span style='color:rgba(255,165,0,1)'>"game"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"dance"</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>                }
<span class='span_code_line'></span>            ]
<span class='span_code_line'></span>        }, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"items"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>                {</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Andy"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>20</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>                        <span style='color:rgba(255,165,0,1)'>"draw"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"sing"</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>                }, {</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Kun"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>26</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>                        <span style='color:rgba(255,165,0,1)'>"sing"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"dance"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"rap"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"basketball"</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>                }
<span class='span_code_line'></span>            ]
<span class='span_code_line'></span>        }
<span class='span_code_line'></span>    ]</span></pre>
</div>
<p>Similarly you can use multiple <span class='mark'>path</span>s for grouping, but unlike <span class='mark'>Sort</span> these <span class='mark'>path</span>s are not grouping the results of the first <span class='mark'>path</span>. They are juxtaposed, not nested.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Group</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>...<span style='color:rgba(255,255,255,1)'>],</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>...<span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>}</span></pre>
</div>
<p>What should I do if I want to do nested <span class='mark'>Group()</span>? The author does not intend to implement it in <span class='mark'>Group()</span>, because <span class='mark'>STJsonPath</span> can do the job.</p>
<div><h2 class='h_option anchor_point' name='b_s'>terms</h2></div>
<p><span class='mark'>Terms()</span> is similar to aggregation in the <span class='mark'>ElasticSearch</span> database, counting the number of occurrences of a field, and like <span class='mark'>Sort()</span>, it can choose whether to specify <span class='mark'>path</span> or multiple <span class='mark'>paths</span>.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Terms</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>        {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"cooking"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"sing"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>3</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"game"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"dance"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>2</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"draw"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"rap"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"basketball"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>    ],</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>        {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>2</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>2</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>    ]
<span class='span_code_line'></span>}</span></pre>
</div>
<p>As you can see, it seems that <span class='mark'>hobby</span> doesn't sort <span class='mark'>count</span>? Yes, it does. This is intentional on the author's part.... What? Not convinced? Is it possible that there is actually a role for <span class='mark'>Terms()</span>? There is a <span class='mark'>cardinality</span> in the <span class='mark'>ES</span> database. It is used to count the number of data in a field after it has been de-duplicated.</p>
<p>Is it possible that the author actually wanted to implement a function like this? But halfway through writing this function, the author Deleted it on the spot. There's no need for that. Isn't the <span class='mark'>Terms()</span> above already doing the job? For example:</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span>json_src<span style='color:rgba(219,112,147,1)'>.Terms</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>)[</span><span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>]</span><span style='color:rgba(112,128,144,1)'>.Count</span><span style='color:rgba(255,255,255,1)'>;</span></pre>
</div>
<p>And is there a possibility that <span class='mark'>cardinality</span> only counts the number of individuals. But.... What if you want to get the values of the de-duplicated fields? And it seems that <span class='mark'>Terms()</span> has already been done in all these cases. It's just not sorting. We already have <span class='mark'>Sort()</span> function, and then a separate order is difficult?</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span>json_src<span style='color:rgba(219,112,147,1)'>.Terms</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>)[</span><span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>]</span><span style='color:rgba(219,112,147,1)'>.Sort</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>);</span></pre>
</div>
<p>What do I have to do if I want to get the top three most popular hobbies for personnel?</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>
<span class='span_code_line'></span>    json_src<span style='color:rgba(219,112,147,1)'>.Terms</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>)[</span><span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>]</span>
<span class='span_code_line'></span>    <span style='color:rgba(219,112,147,1)'>.Sort</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(30,144,255,1)'>true</span><span style='color:rgba(255,255,255,1)'>)</span>
<span class='span_code_line'></span>    <span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"[0:3]"</span><span style='color:rgba(255,255,255,1)'>)</span>
<span class='span_code_line'></span>    <span style='color:rgba(219,112,147,1)'>.Select</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"*.value"</span><span style='color:rgba(255,255,255,1)'>)</span>
<span class='span_code_line'></span>    <span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>)
<span class='span_code_line'></span>    );</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>    <span style='color:rgba(0,255,255,1)'>"sing"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"dance"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"basketball"</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>]</span></pre>
</div>
<div><h2 class='h_option anchor_point' name='b_t'>min, max</h2></div>
<p><span class='mark'>Min()</span> <span class='mark'>Max()</span> is to find the minimum and maximum elements, respectively, and can be specified without or with multiple <span class='mark'>path</span>s.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Min</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>,</span>                 <span style='color:rgba(0,255,0,1)'>// Four of these elements are involved in the calculation.</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>16</span><span style='color:rgba(255,255,255,1)'>,</span>                <span style='color:rgba(0,255,0,1)'>// The minimum age value is 16.</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"items"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>                  <span style='color:rgba(0,255,0,1)'>// The element that satisfies the minimum value.</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tom"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>16</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"cooking"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"sing"</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>            }, {</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"name"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"Tony"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>16</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"gender"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>0</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,165,0,1)'>"hobby"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[</span>
<span class='span_code_line'></span>                    <span style='color:rgba(255,165,0,1)'>"game"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"dance"</span>
<span class='span_code_line'></span>                <span style='color:rgba(255,255,255,1)'>]
<span class='span_code_line'></span>            }
<span class='span_code_line'></span>        ]
<span class='span_code_line'></span>    }
<span class='span_code_line'></span>}</span></pre>
</div>
<p>In fact, the effect above is a bit like <span class='mark'>Group</span> a bit like that, plus a <span class='mark'>Sort()</span>. It's almost exactly the same. Even the author himself is confused. We should have used <span class='mark'>Group()</span> + <span class='mark'>Sort()</span> inside <span class='mark'>Min/Max()</span> to achieve this. Forget about it. The code is written. But it is clear that <span class='mark'>Sort()</span> will certainly reduce efficiency. But then again. The small amount of data does not care about efficiency. But what about big data? Big data volume you give me that you use <span class='mark'>Json</span> array to save ？？？？ Are you sick?</p>
<div><h2 class='h_option anchor_point' name='b_u'>avg, sum</h2></div>
<p><span class='mark'>Avg()</span> <span class='mark'>Sum()</span> is used to calculate the average and the summary, respectively, and can be unspecified or specify multiple <span class='mark'>keys</span>.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Avg</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"age"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>,</span>         <span style='color:rgba(0,255,0,1)'>// Four of these elements are involved in the calculation.</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>19</span><span style='color:rgba(112,128,144,1)'>.</span><span style='color:rgba(144,238,144,1)'>5</span>       <span style='color:rgba(0,255,0,1)'>// avg is 19.5</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>}</span></pre>
</div>
<p>The return value of <span class='mark'>Sum()</span> is the same as <span class='mark'>Avg()</span>, the only difference is that <span class='mark'>value</span> is an average and a summary.</p>
<div><h2 class='h_option anchor_point' name='b_v'>STJsonPath.Name</h2></div>
<p>In the above demo, we have specified a field for data manipulation, and the resulting <span class='mark'>json</span> will output the field name as a <span class='mark'>key</span>. But the above does not emphasize that the operation is performed on the specified <span class='mark'>key</span>, but on the <span class='mark'>path</span>. It's just that the path is simpler to make it look like <span class='mark'>key</span> to us.</p>
<p>What if aggregation is done this way?</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Terms</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"hobby[0]"</span><span style='color:rgba(255,255,255,1)'>)</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"hobby[0]"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>        {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"cooking"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"game"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"draw"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"sing"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>    ]
<span class='span_code_line'></span>}</span></pre>
</div>
<p>It seems like it looks strange. Actually <span class='mark'>STJsonPath</span> has a <span class='mark'>Name</span> property.</p>
<div class='div_code'>
<pre class='pre_code'><span class='span_code_line'></span><span style='color:rgba(0,255,255,1)'>Console</span><span style='color:rgba(219,112,147,1)'>.WriteLine</span><span style='color:rgba(255,255,255,1)'>(</span>json_src<span style='color:rgba(219,112,147,1)'>.Terms</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(30,144,255,1)'>new</span> <span style='color:rgba(0,255,255,1)'>STJsonPath</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(255,165,0,1)'>"test"</span><span style='color:rgba(255,255,255,1)'>,</span> <span style='color:rgba(255,165,0,1)'>"hobby[0]"</span><span style='color:rgba(255,255,255,1)'>))</span><span style='color:rgba(219,112,147,1)'>.ToString</span><span style='color:rgba(255,255,255,1)'>(</span><span style='color:rgba(144,238,144,1)'>4</span><span style='color:rgba(255,255,255,1)'>));</span>
<span class='span_code_line'></span><span style='color:rgba(0,255,0,1)'>/*******************************************************************************
<span class='span_code_line'></span> *                                [output]                                     *
<span class='span_code_line'></span> *******************************************************************************/</span>
<span class='span_code_line'></span><span style='color:rgba(255,255,255,1)'>{</span>
<span class='span_code_line'></span>    <span style='color:rgba(255,165,0,1)'>"test"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,255,255,1)'>[
<span class='span_code_line'></span>        {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"cooking"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"game"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"draw"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}, {</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"value"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(255,165,0,1)'>"sing"</span><span style='color:rgba(255,255,255,1)'>,</span>
<span class='span_code_line'></span>            <span style='color:rgba(255,165,0,1)'>"count"</span><span style='color:rgba(255,255,255,1)'>:</span> <span style='color:rgba(144,238,144,1)'>1</span>
<span class='span_code_line'></span>        <span style='color:rgba(255,255,255,1)'>}
<span class='span_code_line'></span>    ]
<span class='span_code_line'></span>}</span></pre>
</div>
<h1 class='h_title anchor_point' name='b_w'>The END</h1>
<p>Finally, thank you so damn much for seeing it through to the end, the author is about to go crazy writing it. If you encounter any problems during the use, please inform the author in time if you can. The author will certainly be very promptly recorded, as to change or not ...... We'll talk about it later.</p>
<div class='div_hightlight' style='background-color:black;color:white'>
<ul>
<li>TG: DebugST</li>
<li>QQ: 2212233137</li>
<li>Mail: 2212233137@qq.com</li>
</ul>
</div>

</div>
<div id="div_right_list">
<a name='a_a' href='#a_a'>STLib.STJson</a>
<a name='a_b' href='#a_b'>Introduction</a>
<a name='a_c' href='#a_c'>Path question</a>
<a name='a_d' href='#a_d'>Expression question</a>
<a name='a_e' href='#a_e'>STJson API</a>
<a name='a_f' href='#a_f'>Data mapping</a>
<a name='a_g' href='#a_g'>Static functions</a>
<a name='a_h' href='#a_h'>Non-Static functions</a>
<a name='a_i' href='#a_i'>Extended functions</a>
<a name='a_j' href='#a_j'>Fields</a>
<a name='a_k' href='#a_k'>Indexer</a>
<a name='a_l' href='#a_l'>STJson [Basic]</a>
<a name='a_m' href='#a_m'>object -&gt; string</a>
<a name='a_n' href='#a_n'>string -&gt; object</a>
<a name='a_o' href='#a_o'>STJsonConverter</a>
<a name='a_p' href='#a_p'>STJsonAttribute</a>
<a name='a_q' href='#a_q'>STJsonSetting</a>
<a name='a_r' href='#a_r'>json_src</a>
<a name='a_s' href='#a_s'>STJsonPath</a>
<a name='a_t' href='#a_t'>Selector</a>
<a name='a_u' href='#a_u'>How to use</a>
<a name='a_v' href='#a_v'>Wildcard character</a>
<a name='a_w' href='#a_w'>Depth selector</a>
<a name='a_x' href='#a_x'>List selector</a>
<a name='a_y' href='#a_y'>Slice selector</a>
<a name='a_z' href='#a_z'>Expression</a>
<a name='b_a' href='#b_a'>Filter expression</a>
<a name='b_b' href='#b_b'>General expression</a>
<a name='b_c' href='#b_c'>Test expression</a>
<a name='b_d' href='#b_d'>Build-In functions</a>
<a name='b_e' href='#b_e'>Build-In functions list</a>
<a name='b_f' href='#b_f'>Custom functions</a>
<a name='b_g' href='#b_g'>Selectors in expressions</a>
<a name='b_h' href='#b_h'>Select mode</a>
<a name='b_i' href='#b_i'>ParsedTokens</a>
<a name='b_j' href='#b_j'>STJson [Advanced]</a>
<a name='b_k' href='#b_k'>Get value</a>
<a name='b_l' href='#b_l'>Set value</a>
<a name='b_m' href='#b_m'>Callback</a>
<a name='b_n' href='#b_n'>PathItem</a>
<a name='b_o' href='#b_o'>Clone</a>
<a name='b_p' href='#b_p'>Aggregation</a>
<a name='b_q' href='#b_q'>sort</a>
<a name='b_r' href='#b_r'>group</a>
<a name='b_s' href='#b_s'>terms</a>
<a name='b_t' href='#b_t'>min, max</a>
<a name='b_u' href='#b_u'>avg, sum</a>
<a name='b_v' href='#b_v'>STJsonPath.Name</a>
<a name='b_w' href='#b_w'>The END</a>
</div>
</div>
</body>
</html>
